Browse Source

Feature: Mobile - Add sms article type

Vladimir Sheremet 2 years ago
parent
commit
e464997159

+ 5 - 0
app/frontend/apps/mobile/pages/ticket/__tests__/mocks/detail-view.ts

@@ -34,6 +34,11 @@ export const defaultTicket = () =>
       policy: {
         update: true,
       },
+      createArticleType: {
+        id: convertToGraphQLId('TicketArticleType', 5),
+        name: 'email',
+        __typename: 'TicketArticleType',
+      },
       owner: {
         __typename: 'User',
         internalId: 100,

+ 35 - 2
app/frontend/apps/mobile/pages/ticket/composable/useTicketArticleContext.ts

@@ -2,9 +2,11 @@
 
 import type { PopupItem } from '@mobile/components/CommonSectionPopup'
 import { useDialog } from '@shared/composables/useDialog'
-import { computed, ref, shallowRef } from 'vue'
+import { computed, nextTick, ref, shallowRef } from 'vue'
 import type { TicketArticle, TicketById } from '@shared/entities/ticket/types'
 import { createArticleActions } from '@shared/entities/ticket-article/action/plugins'
+import type { TicketArticlePerformOptions } from '@shared/entities/ticket-article/action/plugins/types'
+import { useTicketInformation } from './useTicketInformation'
 
 export const useTicketArticleContext = () => {
   const articleForContext = shallowRef<TicketArticle>()
@@ -16,6 +18,8 @@ export const useTicketArticleContext = () => {
       import('../components/TicketDetailView/ArticleMetadataDialog.vue'),
   })
 
+  const { showArticleReplyDialog, form } = useTicketInformation()
+
   const triggerId = ref(0)
 
   const recalculate = () => {
@@ -27,6 +31,32 @@ export const useTicketArticleContext = () => {
     disposeCallbacks.push(callback)
   }
 
+  const openReplyDialog: TicketArticlePerformOptions['openReplyDialog'] =
+    async (values = {}) => {
+      const formNode = form.value?.formNode
+      if (!formNode) return
+
+      await showArticleReplyDialog()
+
+      const { articleType, ...otherOptions } = values
+
+      formNode.find('articleType')?.input(articleType, false)
+      // trigger new fields that depend on the articleType
+      await nextTick()
+
+      for (const [key, value] of Object.entries(otherOptions)) {
+        const node = formNode.find(key, 'name')
+        node?.input(value, false)
+        // TODO: make handling more generic(?)
+        if (node && (key === 'to' || key === 'cc')) {
+          const options = Array.isArray(value)
+            ? value.map((v) => ({ value: v, label: v }))
+            : [{ value, label: value }]
+          node.emit('prop:options', options)
+        }
+      }
+    }
+
   const contextOptions = computed<PopupItem[]>(() => {
     const ticket = ticketForContext.value
     const article = articleForContext.value
@@ -48,7 +78,10 @@ export const useTicketArticleContext = () => {
         label,
         link,
         onAction: () =>
-          perform(ticket, article, { selection: selectionRange.value }),
+          perform(ticket, article, {
+            selection: selectionRange.value,
+            openReplyDialog,
+          }),
       }
     })
 

+ 6 - 1
app/frontend/apps/mobile/pages/ticket/composable/useTicketEdit.ts

@@ -12,6 +12,7 @@ import { MutationHandler } from '@shared/server/apollo/handler'
 import type { TicketById } from '@shared/entities/ticket/types'
 import type { FileUploaded } from '@shared/components/Form/fields/FieldFile/types'
 import type { SecurityValue } from '@shared/components/Form/fields/FieldSecurity/types'
+import { getNode } from '@formkit/core'
 import { useTicketUpdateMutation } from '../graphql/mutations/update.api'
 
 interface ArticleFormValues {
@@ -19,6 +20,7 @@ interface ArticleFormValues {
   body: string
   internal: boolean
   cc?: string[]
+  inReplyTo?: string
   to?: string[]
   subject?: string
   attachments?: FileUploaded[]
@@ -70,6 +72,8 @@ export const useTicketEdit = (
       pick(file, ['content', 'name', 'type']),
     )
 
+    const contentType = getNode('body')?.context?.contentType || 'text/html'
+
     return {
       type: article.articleType,
       body: article.body,
@@ -77,7 +81,8 @@ export const useTicketEdit = (
       cc: article.cc,
       to: article.to,
       subject: article.subject,
-      contentType: article.contentType || 'text/html',
+      inReplyTo: article.inReplyTo,
+      contentType,
       attachments: attachments.length ? { files, formId } : null,
       security: article.security,
     }

+ 4 - 0
app/frontend/apps/mobile/pages/ticket/composable/useTicketEditForm.ts

@@ -58,6 +58,10 @@ export const useTicketEditForm = (ticket: Ref<TicketById | undefined>) => {
     name: 'article',
     isGroupOrList: true,
     children: [
+      {
+        type: 'hidden',
+        name: 'inReplyTo',
+      },
       {
         name: 'articleType',
         label: __('Article Type'),

+ 1 - 1
app/frontend/apps/mobile/pages/ticket/composable/useTicketInformation.ts

@@ -23,7 +23,7 @@ interface TicketInformation {
   isTicketFormGroupValid: ComputedRef<boolean>
   isArticleFormGroupValid: ComputedRef<boolean>
   formSubmit: () => void
-  showArticleReplyDialog: () => void
+  showArticleReplyDialog: () => Promise<void>
 }
 
 export const useTicketInformation = () => {

+ 1 - 0
app/frontend/apps/mobile/pages/ticket/graphql/fragments/ticketArticleAttributes.api.ts

@@ -12,6 +12,7 @@ export const TicketArticleAttributesFragmentDoc = gql`
       emailAddress
     }
   }
+  messageId
   to {
     raw
     parsed {

+ 1 - 0
app/frontend/apps/mobile/pages/ticket/graphql/fragments/ticketArticleAttributes.graphql

@@ -8,6 +8,7 @@ fragment ticketArticleAttributes on TicketArticle {
       emailAddress
     }
   }
+  messageId
   to {
     raw
     parsed {

+ 3 - 0
app/frontend/apps/mobile/pages/ticket/graphql/fragments/ticketAttributes.api.ts

@@ -63,6 +63,9 @@ export const TicketAttributesFragmentDoc = gql`
   objectAttributeValues {
     ...objectAttributeValues
   }
+  policy {
+    update
+  }
   tags
   subscribed
 }

+ 3 - 0
app/frontend/apps/mobile/pages/ticket/graphql/fragments/ticketAttributes.graphql

@@ -58,6 +58,9 @@ fragment ticketAttributes on Ticket {
   objectAttributeValues {
     ...objectAttributeValues
   }
+  policy {
+    update
+  }
   tags
   subscribed
 }

+ 3 - 2
app/frontend/apps/mobile/pages/ticket/graphql/queries/ticket.api.ts

@@ -13,8 +13,9 @@ export const TicketDocument = gql`
     ticket: {ticketId: $ticketId, ticketInternalId: $ticketInternalId, ticketNumber: $ticketNumber}
   ) {
     ...ticketAttributes
-    policy {
-      update
+    createArticleType {
+      id
+      name
     }
     mentions(first: $mentionsCount) {
       totalCount

Some files were not shown because too many files changed in this diff