TimeAccountingFlyout.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed, reactive } from 'vue'
  4. import Form from '#shared/components/Form/Form.vue'
  5. import type { FormSubmitData } from '#shared/components/Form/types.ts'
  6. import { useForm } from '#shared/components/Form/useForm.ts'
  7. import type { TicketArticleTimeAccountingFormData } from '#shared/entities/ticket/types.ts'
  8. import { EnumFormUpdaterId } from '#shared/graphql/types.ts'
  9. import { i18n } from '#shared/i18n.ts'
  10. import { useApplicationStore } from '#shared/stores/application.ts'
  11. import CommonFlyout from '#desktop/components/CommonFlyout/CommonFlyout.vue'
  12. import type { ActionFooterOptions } from '#desktop/components/CommonFlyout/types.ts'
  13. import { closeFlyout } from '#desktop/components/CommonFlyout/useFlyout.ts'
  14. const emit = defineEmits<{
  15. 'account-time': [TicketArticleTimeAccountingFormData]
  16. skip: []
  17. }>()
  18. const { form } = useForm()
  19. const flyoutName = 'ticket-time-accounting'
  20. const submitForm = (
  21. formData: FormSubmitData<TicketArticleTimeAccountingFormData>,
  22. ) => {
  23. emit('account-time', formData)
  24. closeFlyout(flyoutName)
  25. }
  26. const onClose = (isCancel?: boolean) => {
  27. if (!isCancel) return
  28. emit('skip')
  29. }
  30. const { config } = useApplicationStore()
  31. const timeAccountingUnit = computed(() => {
  32. switch (config.time_accounting_unit) {
  33. case 'hour':
  34. return __('hour(s)')
  35. case 'quarter':
  36. return __('quarter-hour(s)')
  37. case 'minute':
  38. return __('minute(s)')
  39. case 'custom': {
  40. if (config.time_accounting_unit_custom)
  41. return config.time_accounting_unit_custom
  42. return null
  43. }
  44. default:
  45. return null
  46. }
  47. })
  48. const formSchema = [
  49. {
  50. isLayout: true,
  51. component: 'FormGroup',
  52. props: {
  53. class: '@container/form-group',
  54. },
  55. children: [
  56. {
  57. id: 'timeUnit',
  58. name: 'time_unit',
  59. label: __('Accounted Time'),
  60. type: 'text',
  61. required: true,
  62. placeholder: __('Enter the time you want to record'),
  63. validation: 'number',
  64. ...(timeAccountingUnit.value
  65. ? {
  66. sectionsSchema: {
  67. suffix: {
  68. // FIXME: Not working.
  69. // if: '$timeAccountingUnit',
  70. // children: '$timeAccountingUnit',
  71. $el: 'span',
  72. children: i18n.t(timeAccountingUnit.value || ''),
  73. attrs: {
  74. class:
  75. 'py-2.5 px-2.5 outline outline-1 -outline-offset-1 outline-blue-200 dark:outline-gray-700 bg-neutral-50 dark:bg-gray-500 rounded-e-md text-gray-100 dark:text-neutral-400',
  76. },
  77. },
  78. },
  79. }
  80. : {}),
  81. },
  82. {
  83. if: '$timeAccountingTypes === true',
  84. id: 'accountedTimeTypeId',
  85. name: 'accounted_time_type_id',
  86. label: __('Activity Type'),
  87. type: 'select',
  88. props: {
  89. clearable: true,
  90. },
  91. },
  92. ],
  93. },
  94. ]
  95. const timeAccountingTypes = computed(() => config.time_accounting_types)
  96. const schemaData = reactive({
  97. // timeAccountingUnit,
  98. timeAccountingTypes,
  99. })
  100. const footerActionOptions = computed<ActionFooterOptions>(() => ({
  101. actionLabel: __('Account Time'),
  102. actionButton: { variant: 'submit', type: 'submit' },
  103. cancelLabel: __('Skip'),
  104. form: form.value,
  105. }))
  106. </script>
  107. <template>
  108. <CommonFlyout
  109. :header-title="__('Time Accounting')"
  110. :footer-action-options="footerActionOptions"
  111. header-icon="stopwatch"
  112. :name="flyoutName"
  113. no-close-on-action
  114. @close="onClose"
  115. >
  116. <div class="flex flex-col gap-3">
  117. <Form
  118. id="form-ticket-time-accounting"
  119. ref="form"
  120. :schema="formSchema"
  121. :schema-data="schemaData"
  122. should-autofocus
  123. :form-updater-id="
  124. EnumFormUpdaterId.FormUpdaterUpdaterTicketTimeAccounting
  125. "
  126. form-updater-initial-only
  127. @submit="
  128. submitForm(
  129. $event as FormSubmitData<TicketArticleTimeAccountingFormData>,
  130. )
  131. "
  132. />
  133. </div>
  134. </CommonFlyout>
  135. </template>