refactor: enforce 800 line source limits
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import { watch } from 'vue'
|
||||
|
||||
export function useTravelReimbursementApplicationPreviewDateEditor({
|
||||
applicationPreviewEditor,
|
||||
cancelApplicationPreviewEditor,
|
||||
commitApplicationPreviewDateEditor,
|
||||
composerDateMode,
|
||||
composerDatePickerOpen,
|
||||
composerRangeEndDate,
|
||||
composerRangeStartDate,
|
||||
composerSingleDate,
|
||||
formatDateInputValue,
|
||||
isApplicationPreviewEditing,
|
||||
messages,
|
||||
openApplicationPreviewEditor,
|
||||
travelCalculatorOpen
|
||||
}) {
|
||||
function applyLinkedApplicationPreviewDateSelection(selection) {
|
||||
const editor = applicationPreviewEditor.value
|
||||
if (editor.fieldKey !== 'time' || !editor.messageId) {
|
||||
return false
|
||||
}
|
||||
|
||||
const targetMessage = messages.value.find((item) =>
|
||||
String(item.id || '') === String(editor.messageId || '')
|
||||
)
|
||||
if (!targetMessage?.applicationPreview) {
|
||||
return false
|
||||
}
|
||||
|
||||
applicationPreviewEditor.value = {
|
||||
...editor,
|
||||
dateMode: selection.mode === 'range' ? 'range' : 'single',
|
||||
singleDate: selection.startDate,
|
||||
rangeStartDate: selection.startDate,
|
||||
rangeEndDate: selection.endDate || selection.startDate
|
||||
}
|
||||
return commitApplicationPreviewDateEditor(targetMessage)
|
||||
}
|
||||
|
||||
function syncComposerDateFromApplicationEditor() {
|
||||
const editor = applicationPreviewEditor.value
|
||||
const today = formatDateInputValue()
|
||||
composerDateMode.value = editor.dateMode === 'range' ? 'range' : 'single'
|
||||
composerSingleDate.value = editor.singleDate || today
|
||||
composerRangeStartDate.value = editor.rangeStartDate || composerSingleDate.value || today
|
||||
composerRangeEndDate.value = editor.rangeEndDate || composerRangeStartDate.value || today
|
||||
composerDatePickerOpen.value = true
|
||||
travelCalculatorOpen.value = false
|
||||
}
|
||||
|
||||
function openApplicationPreviewEditorFromUi(message, fieldKey, value) {
|
||||
openApplicationPreviewEditor(message, fieldKey, value)
|
||||
if (fieldKey === 'time' && isApplicationPreviewEditing(message, 'time')) {
|
||||
syncComposerDateFromApplicationEditor()
|
||||
}
|
||||
}
|
||||
|
||||
watch(composerDatePickerOpen, (open, previousOpen) => {
|
||||
if (!open && previousOpen && applicationPreviewEditor.value.fieldKey === 'time') {
|
||||
cancelApplicationPreviewEditor()
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
applyLinkedApplicationPreviewDateSelection,
|
||||
openApplicationPreviewEditorFromUi
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user