TimeAccountingFlyout.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 submitForm = (
  20. formData: FormSubmitData<TicketArticleTimeAccountingFormData>,
  21. ) => {
  22. emit('account-time', formData)
  23. closeFlyout('ticket-time-accounting')
  24. }
  25. const onClose = (isCancel?: boolean) => {
  26. if (!isCancel) return
  27. emit('skip')
  28. }
  29. const { config } = useApplicationStore()
  30. const timeAccountingUnit = computed(() => {
  31. switch (config.time_accounting_unit) {
  32. case 'hour':
  33. return __('hour(s)')
  34. case 'quarter':
  35. return __('quarter-hour(s)')
  36. case 'minute':
  37. return __('minute(s)')
  38. case 'custom': {
  39. if (config.time_accounting_unit_custom)
  40. return config.time_accounting_unit_custom
  41. return null
  42. }
  43. default:
  44. return null
  45. }
  46. })
  47. const formSchema = [
  48. {
  49. isLayout: true,
  50. component: 'FormGroup',
  51. props: {
  52. class: '@container/form-group',
  53. },
  54. children: [
  55. {
  56. id: 'timeUnit',
  57. name: 'time_unit',
  58. label: __('Accounted Time'),
  59. type: 'text',
  60. required: true,
  61. placeholder: __('Enter the time you want to record'),
  62. validation: 'number',
  63. ...(timeAccountingUnit.value
  64. ? {
  65. sectionsSchema: {
  66. suffix: {
  67. // FIXME: Not working.
  68. // if: '$timeAccountingUnit',
  69. // children: '$timeAccountingUnit',
  70. $el: 'span',
  71. children: i18n.t(timeAccountingUnit.value || ''),
  72. attrs: {
  73. class:
  74. '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',
  75. },
  76. },
  77. },
  78. }
  79. : {}),
  80. },
  81. {
  82. if: '$timeAccountingTypes === true',
  83. id: 'accountedTimeTypeId',
  84. name: 'accounted_time_type_id',
  85. label: __('Activity Type'),
  86. type: 'select',
  87. props: {
  88. clearable: true,
  89. },
  90. },
  91. ],
  92. },
  93. ]
  94. const timeAccountingTypes = computed(() => config.time_accounting_types)
  95. const schemaData = reactive({
  96. // timeAccountingUnit,
  97. timeAccountingTypes,
  98. })
  99. const footerActionOptions = computed<ActionFooterOptions>(() => ({
  100. actionLabel: __('Account Time'),
  101. actionButton: { variant: 'submit', type: 'submit' },
  102. cancelLabel: __('Skip'),
  103. form: form.value,
  104. }))
  105. </script>
  106. <template>
  107. <CommonFlyout
  108. :header-title="__('Time Accounting')"
  109. :footer-action-options="footerActionOptions"
  110. header-icon="stopwatch"
  111. name="ticket-time-accounting"
  112. no-close-on-action
  113. @close="onClose"
  114. >
  115. <div class="flex flex-col gap-3">
  116. <Form
  117. id="form-ticket-time-accounting"
  118. ref="form"
  119. :schema="formSchema"
  120. :schema-data="schemaData"
  121. :form-updater-id="
  122. EnumFormUpdaterId.FormUpdaterUpdaterTicketTimeAccounting
  123. "
  124. form-updater-initial-only
  125. @submit="
  126. submitForm(
  127. $event as FormSubmitData<TicketArticleTimeAccountingFormData>,
  128. )
  129. "
  130. />
  131. </div>
  132. </CommonFlyout>
  133. </template>