IssueTrackerLinkFlyout.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import Form from '#shared/components/Form/Form.vue'
  4. import { useForm } from '#shared/components/Form/useForm.ts'
  5. import CommonFlyout from '#desktop/components/CommonFlyout/CommonFlyout.vue'
  6. import { closeFlyout } from '#desktop/components/CommonFlyout/useFlyout.ts'
  7. import type { SubmitData } from '#desktop/pages/ticket/components/TicketSidebar/TicketSidebarExternalIssueTracker/types.ts'
  8. import type { FormKitNode } from '@formkit/core'
  9. interface Props {
  10. name: string
  11. icon: string
  12. label: string
  13. inputPlaceholder: string
  14. issueLinks: string[]
  15. onSubmit: (link: string) => Promise<unknown>
  16. }
  17. const props = defineProps<Props>()
  18. const { form } = useForm()
  19. const validationRuleUrlAlreadyExists = (node: FormKitNode) => {
  20. if (!node.value) return true
  21. return !props.issueLinks.includes(node.value as string)
  22. }
  23. const linkSchema = [
  24. {
  25. name: 'link',
  26. type: 'url',
  27. placeholder: props.inputPlaceholder,
  28. label: __('Issue URL'),
  29. validationRules: {
  30. validationRuleUrlAlreadyExists,
  31. },
  32. validation: 'validationRuleUrlAlreadyExists|url',
  33. validationMessages: {
  34. validationRuleUrlAlreadyExists: __('The issue reference already exists.'),
  35. },
  36. required: true,
  37. },
  38. ]
  39. const submitLink = async (data: SubmitData) => {
  40. const { link } = data
  41. await props.onSubmit(link)
  42. return () => {
  43. closeFlyout(props.name)
  44. }
  45. }
  46. </script>
  47. <template>
  48. <CommonFlyout
  49. :header-icon="icon"
  50. :header-title="label"
  51. :name="name"
  52. no-close-on-action
  53. :footer-action-options="{
  54. actionButton: {
  55. type: 'submit',
  56. },
  57. actionLabel: $t('Link Issue'),
  58. form: form,
  59. }"
  60. >
  61. <Form
  62. ref="form"
  63. :schema="linkSchema"
  64. should-autofocus
  65. @submit="submitLink($event as SubmitData)"
  66. />
  67. </CommonFlyout>
  68. </template>