TicketActionChangeCustomerDialog.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { toRef } 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 { useConfirmation } from '#shared/composables/useConfirmation.ts'
  8. import { useTicketChangeCustomer } from '#shared/entities/ticket/composables/useTicketChangeCustomer.ts'
  9. import { useTicketFormOrganizationHandler } from '#shared/entities/ticket/composables/useTicketFormOrganizationHandler.ts'
  10. import type {
  11. TicketById,
  12. TicketCustomerUpdateFormData,
  13. } from '#shared/entities/ticket/types.ts'
  14. import { defineFormSchema } from '#shared/form/defineFormSchema.ts'
  15. import { EnumObjectManagerObjects } from '#shared/graphql/types.ts'
  16. import CommonButton from '#mobile/components/CommonButton/CommonButton.vue'
  17. import CommonDialog from '#mobile/components/CommonDialog/CommonDialog.vue'
  18. import { closeDialog } from '#mobile/composables/useDialog.ts'
  19. export interface Props {
  20. name: string
  21. ticket: TicketById
  22. }
  23. const props = defineProps<Props>()
  24. const { form, isDirty, canSubmit } = useForm()
  25. const { waitForConfirmation } = useConfirmation()
  26. const cancelDialog = async () => {
  27. if (isDirty.value) {
  28. const confirmed = await waitForConfirmation(
  29. __('Are you sure? You have unsaved changes that will get lost.'),
  30. {
  31. buttonLabel: __('Discard changes'),
  32. buttonVariant: 'danger',
  33. },
  34. )
  35. if (!confirmed) return
  36. }
  37. closeDialog(props.name)
  38. }
  39. const formSchema = defineFormSchema([
  40. {
  41. name: 'customer_id',
  42. screen: 'edit',
  43. object: EnumObjectManagerObjects.Ticket,
  44. required: true,
  45. },
  46. {
  47. name: 'organization_id',
  48. screen: 'edit',
  49. object: EnumObjectManagerObjects.Ticket,
  50. },
  51. ])
  52. const { changeCustomer } = useTicketChangeCustomer(toRef(props, 'ticket'), {
  53. onSuccess: () => closeDialog(props.name),
  54. })
  55. </script>
  56. <template>
  57. <CommonDialog
  58. class="w-full"
  59. no-autofocus
  60. :name="name"
  61. :label="__('Change customer')"
  62. >
  63. <template #before-label>
  64. <CommonButton transparent-background @click="cancelDialog">
  65. {{ $t('Cancel') }}
  66. </CommonButton>
  67. </template>
  68. <template #after-label>
  69. <CommonButton
  70. :form="name"
  71. :disabled="!canSubmit"
  72. variant="primary"
  73. type="submit"
  74. transparent-background
  75. >
  76. {{ $t('Save') }}
  77. </CommonButton>
  78. </template>
  79. <Form
  80. :id="name"
  81. ref="form"
  82. class="w-full p-4"
  83. should-autofocus
  84. :schema="formSchema"
  85. :handlers="[useTicketFormOrganizationHandler()]"
  86. :initial-entity-object="ticket"
  87. use-object-attributes
  88. @submit="
  89. changeCustomer($event as FormSubmitData<TicketCustomerUpdateFormData>)
  90. "
  91. />
  92. </CommonDialog>
  93. </template>