@@ -10,7 +10,7 @@ import Banner from '@/components/common/Banner.vue';
1010import Divider from ' @/components/common/Divider.vue' ;
1111import { Button , Card , useConfirm , ToggleSwitch , useToast } from ' @/lib/primevue' ;
1212import { userService } from ' @/services' ;
13- import { useAuthZStore , useProjectStore } from ' @/store' ;
13+ import { useAuthZStore , useEnquiryStore , useProjectStore } from ' @/store' ;
1414import { GroupName } from ' @/utils/enums/application' ;
1515import { formatDate } from ' @/utils/formatters' ;
1616import { projectRouteNameKey } from ' @/utils/keys' ;
@@ -33,24 +33,31 @@ const { noteHistory = undefined } = defineProps<{
3333 noteHistory? : NoteHistory ;
3434}>();
3535
36+ const NOTES_TAB_INDEX = {
37+ ENQUIRY: 1 ,
38+ SUBMISSION: 3
39+ };
40+
3641// Composables
3742const { t } = useI18n ();
3843const authzStore = useAuthZStore ();
3944const confirmDialog = useConfirm ();
45+ const enquiryStore = useEnquiryStore ();
4046const projectStore = useProjectStore ();
4147const router = useRouter ();
4248const toast = useToast ();
4349const { options } = useCodeStore ();
4450
4551// Store
4652const { getProject } = storeToRefs (projectStore );
53+ const { getEnquiry } = storeToRefs (enquiryStore );
4754
4855// State
56+ const createdByFullNames: Ref <Record <string , string >> = ref ({});
4957const formRef: Ref <InstanceType <typeof Form > | null > = ref (null );
5058const initialFormValues: Ref <any | undefined > = ref (undefined );
51- const visible = defineModel <boolean >(' visible' );
5259const shownToProponent: Ref <boolean > = ref (false );
53- const createdByFullNames : Ref < Record < string , string >> = ref ({} );
60+ const visible = defineModel < boolean >( ' visible ' );
5461
5562// Injections
5663const projectRouteName = inject (projectRouteNameKey );
@@ -61,12 +68,7 @@ const formSchema = object({
6168 .nullable ()
6269 .when (' type' , {
6370 is : (type : string ) => type === NoteType .BRING_FORWARD ,
64- then : (schema ) =>
65- schema .test (
66- ' bring forward required' ,
67- ' Bring forward date is a required field' ,
68- (value ) => value instanceof Date
69- ),
71+ then : (schema ) => schema .required (t (' note.noteForm.bfDateReqd' )),
7072 otherwise : (schema ) => schema .nullable ()
7173 })
7274 .label (' Bring forward date' ),
@@ -79,25 +81,37 @@ const formSchema = object({
7981 .label (' Bring forward state' ),
8082 note: string ().label (' Note' ),
8183 type: string ().oneOf (NOTE_TYPE_LIST ).label (' Note type' ),
82- title: string ().required ().max (255 , ' Title too long' ).label (' Title' )
84+ title: string ().required ().max (255 , ' Title too long' ).label (' Title' ),
85+ escalationType: mixed ()
86+ .when ([' escalateToSupervisor' , ' escalateToDirector' ], {
87+ is : (escalateToSupervisor : boolean , escalateToDirector : boolean ) => escalateToSupervisor || escalateToDirector ,
88+ then : (schema ) => schema .required (t (' note.noteForm.escalationTypeReqd' )),
89+ otherwise : (schema ) => schema .nullable ()
90+ })
91+ .label (' Escalation type' )
8392});
8493
8594function initializeFormValues() {
8695 if (noteHistory ) {
8796 initialFormValues .value = {
88- activityId: noteHistory ? .activityId ,
97+ activityId: noteHistory .activityId ,
8998 bringForwardDate: noteHistory ?.bringForwardDate ? new Date (noteHistory .bringForwardDate ) : null ,
9099 bringForwardState: noteHistory ?.bringForwardState ?? null ,
91100 escalateToSupervisor: noteHistory ?.escalateToSupervisor ,
92101 escalateToDirector: noteHistory ?.escalateToDirector ,
93102 escalationType: noteHistory ?.escalationType ,
94- noteHistoryId: noteHistory ? .noteHistoryId ,
95- type: noteHistory ? .type ?? NoteType . GENERAL ,
96- title: noteHistory ? .title
103+ noteHistoryId: noteHistory .noteHistoryId ,
104+ type: noteHistory .type ,
105+ title: noteHistory .title
97106 };
98107 shownToProponent .value = noteHistory .shownToProponent ;
108+ } else {
109+ initialFormValues .value = {
110+ type: NoteType .GENERAL
111+ };
99112 }
100113}
114+ // }
101115
102116function onInvalidSubmit(e : any ) {
103117 scrollToFirstError (e .errors );
@@ -106,20 +120,20 @@ function onInvalidSubmit(e: any) {
106120function onDelete() {
107121 if (noteHistory ) {
108122 confirmDialog .require ({
109- message: t (shownToProponent .value ? ' noteHistoryModal. deleteMessageIfShown' : ' noteHistoryModal .deleteMessage' ),
110- header: t (' noteHistoryModal .deleteHeader' ),
111- acceptLabel: t (' noteHistoryModal .confirm' ),
123+ message: t (shownToProponent .value ? ' note.noteForm. deleteMessageIfShown' : ' note.noteForm .deleteMessage' ),
124+ header: t (' note.noteForm .deleteHeader' ),
125+ acceptLabel: t (' note.noteForm .confirm' ),
112126 acceptClass: ' p-button-danger' ,
113- rejectLabel: t (' noteHistoryModal .cancel' ),
127+ rejectLabel: t (' note.noteForm .cancel' ),
114128 rejectProps: { outlined: true },
115129 accept : () => {
116130 noteHistoryService
117131 .deleteNoteHistory (noteHistory ?.noteHistoryId as string )
118132 .then (() => {
119- toast .success (t (' noteHistoryModal .noteDeleted' ));
120- toTheProject ();
133+ toast .success (t (' note.noteForm .noteDeleted' ));
134+ getProject . value ? toTheProject () : toTheEnquiry ();
121135 })
122- .catch ((e : any ) => toast .error (t (' noteHistoryModal .noteDeleteFailed' ), e .message ));
136+ .catch ((e : any ) => toast .error (t (' note.noteForm .noteDeleteFailed' ), e .message ));
123137 }
124138 });
125139 }
@@ -145,20 +159,20 @@ async function onSubmit(data: any) {
145159 if (! noteHistory ) {
146160 await noteHistoryService .createNoteHistory ({
147161 ... body ,
148- activityId: getProject .value ?.activityId ,
162+ activityId: getProject .value ?.activityId || getEnquiry . value ?. activityId ,
149163 note: data .note
150164 });
151165 } else {
152166 await noteHistoryService .updateNoteHistory (data .noteHistoryId , {
153167 ... body ,
154- activityId: getProject .value ?.activityId ,
168+ activityId: getProject .value ?.activityId || getEnquiry . value ?. activityId ,
155169 note: data .note
156170 });
157171 }
158- toast .success (t (' noteHistoryModal .noteSaved' ));
159- toTheProject ();
172+ toast .success (t (' note.noteForm .noteSaved' ));
173+ getProject . value ? toTheProject () : toTheEnquiry ();
160174 } catch (e : any ) {
161- toast .error (t (' noteHistoryModal .noteSaveFailed' ), e .message );
175+ toast .error (t (' note.noteForm .noteSaveFailed' ), e .message );
162176 } finally {
163177 visible .value = false ;
164178 }
@@ -167,6 +181,7 @@ async function onSubmit(data: any) {
167181function onTypeChange(e : SelectChangeEvent ) {
168182 if (e .value === NoteType .BRING_FORWARD ) {
169183 formRef .value ?.setFieldValue (' bringForwardState' , BringForwardType .UNRESOLVED );
184+ shownToProponent .value = false ;
170185 }
171186}
172187
@@ -183,7 +198,17 @@ function toTheProject() {
183198 name: projectRouteName ?.value ,
184199 params: { projectId: getProject .value ?.projectId },
185200 query: {
186- initialTab: ' 3'
201+ initialTab: NOTES_TAB_INDEX .SUBMISSION
202+ }
203+ });
204+ }
205+
206+ function toTheEnquiry() {
207+ router .push ({
208+ name: projectRouteName ?.value ,
209+ params: { enquiryId: getEnquiry .value ?.enquiryId },
210+ query: {
211+ initialTab: NOTES_TAB_INDEX .ENQUIRY
187212 }
188213 });
189214}
@@ -199,13 +224,13 @@ onBeforeMount(async () => {
199224<template >
200225 <div class =" flex flex-row gap-x-3 my-4" >
201226 <div class =" flex flex-row gap-x-1" >
202- <span class =" text-[var(--p-bcblue-900)]" >{{ t('noteHistoryModal .created') }}:</span >
227+ <span class =" text-[var(--p-bcblue-900)]" >{{ t('note.noteForm .created') }}:</span >
203228 <span >
204229 {{ formatDate(noteHistory?.createdAt || new Date().toISOString()) }}
205230 </span >
206231 </div >
207232 <div class =" flex flex-row gap-x-1" >
208- <span class =" text-[var(--p-bcblue-900)]" >{{ t('noteHistoryModal .lastUpdated') }}:</span >
233+ <span class =" text-[var(--p-bcblue-900)]" >{{ t('note.noteForm .lastUpdated') }}:</span >
209234 <span >{{ formatDate(noteHistory?.updatedAt) }}</span >
210235 </div >
211236 </div >
@@ -259,12 +284,12 @@ onBeforeMount(async () => {
259284 v-if =" values.type === NoteType.GENERAL"
260285 class =" flex flex-col gap-y-4"
261286 >
262- <span class =" font-bold" >{{ t('noteHistoryModal .showProponent') }}</span >
287+ <span class =" font-bold" >{{ t('note.noteForm .showProponent') }}</span >
263288 <ToggleSwitch
264289 v-model =" shownToProponent "
265290 class="mr-1"
266291 name="shownToProponent"
267- :label =" t (' noteHistoryModal .showProponent' )"
292+ :label =" t (' note.noteForm .showProponent' )"
268293 />
269294 </div >
270295
@@ -275,13 +300,13 @@ onBeforeMount(async () => {
275300 <Checkbox
276301 v-if =" authzStore .isInGroup ([GroupName .NAVIGATOR , GroupName .NAVIGATOR_READ_ONLY ])"
277302 name="escalateToSupervisor"
278- :label =" t (' noteHistoryModal .escalateToSupervisor' )"
303+ :label =" t (' note.noteForm .escalateToSupervisor' )"
279304 :bold =" false "
280305 />
281306 <Checkbox
282307 v-if =" authzStore .isInGroup ([GroupName .ADMIN , GroupName .DEVELOPER , GroupName .SUPERVISOR ])"
283308 name="escalateToDirector"
284- :label =" t (' noteHistoryModal .escalateToDirector' )"
309+ :label =" t (' note.noteForm .escalateToDirector' )"
285310 :bold =" false "
286311 />
287312 <DatePicker
@@ -328,7 +353,7 @@ onBeforeMount(async () => {
328353 icon="pi pi-times"
329354 @click ="
330355 () => {
331- toTheProject ();
356+ getProject ? toTheProject () : toTheEnquiry ();
332357 }
333358 "
334359 />
0 commit comments