From fe0d48703b3949f741950be223e1ff595bd17615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9rik=20BENOIST?= Date: Tue, 20 Feb 2024 00:13:23 +0100 Subject: [PATCH] feat: chat-rct --- src/plugins/i18n/locales/ar.json | 15 ++ src/plugins/i18n/locales/en.json | 15 ++ src/plugins/i18n/locales/fr.json | 15 ++ src/stores/chatrct.store.ts | 111 ++++++++-- .../pages/chat/rct/view/ChatRctWizard.vue | 203 +++++++++++------- 5 files changed, 268 insertions(+), 91 deletions(-) diff --git a/src/plugins/i18n/locales/ar.json b/src/plugins/i18n/locales/ar.json index c3a97c7..285b0b6 100755 --- a/src/plugins/i18n/locales/ar.json +++ b/src/plugins/i18n/locales/ar.json @@ -126,6 +126,21 @@ "Note: Click on the button below to access DOTSOFT Back-office": "Note: Click on the button below to access DOTSOFT Back-office", "Open Back-office": "Open Back-office", "Mount drive": "Mount drive", + "Chat RCT": "Chat RCT", + "Your RCT Item": "Your RCT Item", + "Store Distributor": "Store Distributor", + "Possible actions to realize": "Possible actions to realize", + "Store where item is required": "Store where item is required", + "Specify an RCT": "Specify an RCT", + "Previous": "Previous", + "Next": "Next", + "Select distributor": "Select distributor", + "Select store": "Select store", + "Yes": "Yes", + "No": "No", + "Resend RCT": "Resend RCT ?", + "Summary": "Summary", + "The request has been processed successfully": "The request has been processed successfully", "---------------------------": "---------------------------", "UI Elements": "عناصر واجهة المستخدم", "Forms & Tables": "النماذج والجداول", diff --git a/src/plugins/i18n/locales/en.json b/src/plugins/i18n/locales/en.json index 226ada8..58525f5 100755 --- a/src/plugins/i18n/locales/en.json +++ b/src/plugins/i18n/locales/en.json @@ -126,6 +126,21 @@ "Note: Click on the button below to access DOTSOFT Back-office": "Note: Click on the button below to access DOTSOFT Back-office", "Open Back-office": "Open Back-office", "Mount drive": "Mount drive", + "Chat RCT": "Chat RCT", + "Your RCT Item": "Your RCT Item", + "Store Distributor": "Store Distributor", + "Store where item is required": "Store where item is required", + "Possible actions to realize": "Possible actions to realize", + "Specify an RCT": "Specify an RCT", + "Previous": "Previous", + "Next": "Next", + "Select distributor": "Select distributor", + "Select store": "Select store", + "Yes": "Yes", + "No": "No", + "Resend RCT": "Resend RCT ?", + "Summary": "Summary", + "The request has been processed successfully": "The request has been processed successfully", "---------------------------": "---------------------------", "UI Elements": "UI Elements", "Forms & Tables": "Forms & Tables", diff --git a/src/plugins/i18n/locales/fr.json b/src/plugins/i18n/locales/fr.json index f7e044e..c7d5e6a 100755 --- a/src/plugins/i18n/locales/fr.json +++ b/src/plugins/i18n/locales/fr.json @@ -127,6 +127,21 @@ "Note: Click on the button below to access DOTSOFT Back-office": "Note: Cliquez sur le bouton ci-dessous pour accéder au Back-office DOTSOFT", "Open Back-office": "Ouvrir DOTSOFT", "Mount drive": "Monter lecteur", + "Chat RCT": "Chat RCT", + "Your RCT Item": "RCT recherchée", + "Store Distributor": "Sélection distributeur", + "Store where item is required": "Sélection Boutique", + "Possible actions to realize": "Actions possibles à effectuer", + "Specify an RCT": "Saisissez la RCT", + "Previous": "Précédent", + "Next": "Suivant", + "Select distributor": "Selectionner un distributeur", + "Select store": "Selectionner une boutique", + "Yes": "Oui", + "No": "Non", + "Resend RCT": "Renvoyer RCT ?", + "Summary": "Résumé", + "The request has been processed successfully": "La demande a été traitée avec succès", "---------------------------": "---------------------------", "UI Elements": "ÉLÉMENTS DE L'UI", "Forms & Tables": "Formulaires et tableaux", diff --git a/src/stores/chatrct.store.ts b/src/stores/chatrct.store.ts index 31e544a..3ad08d0 100644 --- a/src/stores/chatrct.store.ts +++ b/src/stores/chatrct.store.ts @@ -1,13 +1,21 @@ export const useChatRctStore = defineStore('chatrct', { state: () => ({ - rct: 'XY10000-08-3A', + ref_rct: null, + ref_r: null, id_produit: 0, distributor: null, - store: 4, + distributor_list: [], + store: null, + store_list: [], prompt_rct: '### Bonjour,\n Indiquez-moi la RCT sur laquelle vous souhaitez faire des recherches ...', prompt_distributor: '', prompt_store: '', + output_actions: '', loading: false, + actions_lib: [], + actions_flag: false, + actions_proc: 'cache', + resend_data: 'No', prompt_gen() { return `${this.prompt_rct}\n${this.prompt_distributor}\n${this.prompt_store}` }, @@ -16,11 +24,16 @@ export const useChatRctStore = defineStore('chatrct', { async validateRct() { this.loading = true - const { data } = await useApi(`/chatrct/rct/${this.rct}`) + const { data } = await useApi(`/chatrct/rct?itemId=${this.ref_rct}`) if (data.value) { const jsonData = JSON.parse(data.value) - this.id_produit = jsonData.response.id_produit + if (jsonData.response.id_produit) { + this.id_produit = jsonData.response.id_produit + this.ref_r = jsonData.response.ref_r + this.distributor_list = jsonData.response.distributor_list + } + else { this.id_produit = 0 } this.prompt_store = '' this.prompt_distributor = '' @@ -29,43 +42,103 @@ export const useChatRctStore = defineStore('chatrct', { this.loading = false - return true // TODO A VERIFIER SI REF N'EXISTE PAS + return (this.id_produit > 0) }, async validateDistributor() { this.loading = true - const { data } = await useApi(`/chatrct/distributor/${this.distributor}?itemId=${this.rct}&produitId=${this.id_produit}`) + const { data } = await useApi(`/chatrct/distributor/${this.distributor}?itemId=${this.ref_rct}&produitId=${this.id_produit}`) if (data.value) { const jsonData = JSON.parse(data.value) this.prompt_distributor = jsonData.response.lines.join('\n') + this.store = null + this.store_list = jsonData.response.store_list } this.loading = false return true }, - setRct(rct: string) { - this.rct = rct + async validateStore() { + this.loading = true + + const { data } = await useApi(`/chatrct/store/${this.store}?distributorId=${this.distributor}&itemId=${this.ref_rct}&produitId=${this.id_produit}`) + if (data.value) { + const jsonData = JSON.parse(data.value) + + this.prompt_store = jsonData.response.lines.join('\n') + this.actions_lib = jsonData.response.actions + this.actions_flag = jsonData.response.actions_flag + this.actions_proc = jsonData.response.actions_proc + } + + this.loading = false + + return true + }, + async validateActions() { + this.loading = true + + if (this.actions_proc === 'cache') { + const currentDate = new Date().toISOString().slice(0, 10).replace(/-/g, '') + + const requestBodyCache = { + itemId: this.ref_r, + comment: `HDPOS Force Cache ${currentDate}`, + proc: this.actions_proc, + } + + const { data } = await useApi('/chatrct/rct/forceCache', { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(requestBodyCache), + }) + + if (data.value) + this.output_actions = data.value.output + } + else if (this.actions_proc === 'exception') { + const tomorrowDate = new Date(Date.now() + 86400000).toISOString().slice(0, 10).replace(/-/g, '') + + const requestBodyException = { + id_produit: this.id_produit, + id_distrib: this.distributor, + fdate: tomorrowDate, + forcer_cache: 1, + modul_trait: 'HDPOS', + } + + const { data } = await useApi('/chatrct/rct/forceException', { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(requestBodyException), + }) + + if (data.value) + this.output_actions = data.value.output + } + + this.loading = false + + // Check for "ERREUR" at the beginning of the string + return !this.output_actions.startsWith('ERREUR') }, clearState() { - this.rct = '' + this.ref_rct = null this.distributor = null this.store = null + this.resend_data = 'No' }, - getRct() { - return this.rct - }, - getDistrib() { - return this.distributor - }, - getStore() { - return this.store - }, - ClearPrompts() { + clearPrompts() { this.prompt_rct = '### Bonjour,\n Indiquez-moi la RCT sur laquelle vous souhaitez faire des recherches ...' this.prompt_distributor = '' this.prompt_store = '' + this.output_actions = '' }, }, }) diff --git a/src/views/pages/chat/rct/view/ChatRctWizard.vue b/src/views/pages/chat/rct/view/ChatRctWizard.vue index 1ca0b10..ff65445 100644 --- a/src/views/pages/chat/rct/view/ChatRctWizard.vue +++ b/src/views/pages/chat/rct/view/ChatRctWizard.vue @@ -2,33 +2,24 @@ import { VForm } from 'vuetify/components/VForm' import { useChatRctStore } from '@stores/chatrct.store' +const { t } = useI18n() + const numberedSteps = [ { - title: 'Item', - subtitle: 'Your RCT Item', + title: t('Item'), + subtitle: t('Your RCT Item'), }, { - title: 'Distributor', - subtitle: 'Store Distributor', + title: t('Distributor'), + subtitle: t('Store Distributor'), }, { - title: 'Store', - subtitle: 'Store where item is sold', + title: t('Store'), + subtitle: t('Store where item is required'), }, { - title: 'Actions', - subtitle: 'Possible actions to realize', - }, -] - -const distributors = [ - { - name: 'IKKS', - id: 1, - }, - { - name: 'XO', - id: 6, + title: t('Actions'), + subtitle: t('Possible actions to realize'), }, ] @@ -40,8 +31,13 @@ const refDistributorForm = ref() const refStoreForm = ref() const refActionsForm = ref() +const isSnackbarActions = ref(false) + const store = useChatRctStore() +store.clearState() +store.clearPrompts() + const validateRctForm = async () => { const validRctForm = await refRctForm.value?.validate() if (validRctForm && validRctForm.valid) { @@ -51,9 +47,7 @@ const validateRctForm = async () => { currentStep.value++ isCurrentStepValid.value = true } - else { - isCurrentStepValid.value = false - } + else { isCurrentStepValid.value = false } } } @@ -66,41 +60,57 @@ const validateDistributorForm = async () => { currentStep.value++ isCurrentStepValid.value = true } - else { - isCurrentStepValid.value = false - } + else { isCurrentStepValid.value = false } } } -const validateStoreForm = () => { - refStoreForm.value?.validate().then(valid => { - if (valid) { - currentStep.value++ - isCurrentStepValid.value = true +const validateStoreForm = async () => { + const validStoreForm = await refStoreForm.value?.validate() + if (validStoreForm && validStoreForm.valid) { + if (store.store_list && Array.isArray(store.store_list) && store.store_list.length > 0) { + const valid = store.store_list.some((s: { id: any }) => s.id === store.store) + const validStore = await store.validateStore() + + if (valid && validStore) { + currentStep.value++ + isCurrentStepValid.value = true + } + else { isCurrentStepValid.value = false } } - else { - isCurrentStepValid.value = false - } - }) + else { isCurrentStepValid.value = false } + } } -const validateActionsForm = () => { - isCurrentStepValid.value = true +const validateActionsForm = async () => { + const validActionsForm = await refActionsForm.value?.validate() + if (validActionsForm && validActionsForm.valid) { + if (store.resend_data === 'Yes') { + const valid = await store.validateActions() - // refActionsForm.value?.validate().then(valid => { - // if (valid.valid) - // isCurrentStepValid.value = true - // else isCurrentStepValid.value = false - // }) + if (valid) { + currentStep.value++ + isCurrentStepValid.value = true + isSnackbarActions.value = true + } + else { isCurrentStepValid.value = false } + } + else { isCurrentStepValid.value = false } + } } const decrementStep = () => { currentStep.value-- - if (currentStep.value === 0) - store.ClearPrompts() - else if (currentStep.value === 1) + if (currentStep.value === 0) { + store.clearPrompts() + } + else if (currentStep.value === 1) { store.prompt_distributor = '' + } + else if (currentStep.value === 2) { + store.prompt_store = '' + store.output_actions = '' + } } @@ -132,10 +142,10 @@ const decrementStep = () => {
- Item + {{ $t('Item') }}

- Your RCT Item + {{ $t('Your RCT Item') }}

@@ -144,8 +154,8 @@ const decrementStep = () => { md="6" > @@ -163,11 +173,11 @@ const decrementStep = () => { start class="flip-in-rtl" /> - Previous + {{ $t('Previous') }} - Next + {{ $t('Next') }} {
- Distributor + {{ $t('Distributor') }}

- Distributor where item are sold + {{ $t('Store Distributor') }}

@@ -202,12 +212,13 @@ const decrementStep = () => { > @@ -222,11 +233,11 @@ const decrementStep = () => { start class="flip-in-rtl" /> - Previous + {{ $t('Previous') }}
- Next + {{ $t('Next') }} {
- Store search + {{ $t('Store') }}

- Possible store to search data on ... + {{ $t('Store where item is required') }}

@@ -259,11 +270,15 @@ const decrementStep = () => { cols="12" md="6" > - @@ -279,11 +294,11 @@ const decrementStep = () => { start class="flip-in-rtl" /> - Previous + {{ $t('Previous') }}
- Next + {{ $t('Next') }} { > -
- List of Actions -
+

+ {{ action }} +

- + sm="8" + > + + + + + + + {{ store.output_actions }} +
@@ -326,19 +368,36 @@ const decrementStep = () => { start class="flip-in-rtl" /> - Previous + {{ $t('Previous') }} - submit + {{ $t('Submit') }}
+ + + {{ $t('The request has been processed successfully') }} + + +