@@ -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' ;
@@ -29,28 +29,36 @@ import type { SelectChangeEvent } from 'primevue/select';
2929import type { NoteHistory } from ' @/types' ;
3030
3131// Props
32- const { noteHistory = undefined } = defineProps <{
32+ const { editable, noteHistory = undefined } = defineProps <{
33+ editable? : boolean ;
3334 noteHistory? : NoteHistory ;
3435}>();
3536
37+ const NOTES_TAB_INDEX = {
38+ ENQUIRY: 1 ,
39+ SUBMISSION: 3
40+ };
41+
3642// Composables
3743const { t } = useI18n ();
3844const authzStore = useAuthZStore ();
3945const confirmDialog = useConfirm ();
46+ const enquiryStore = useEnquiryStore ();
4047const projectStore = useProjectStore ();
4148const router = useRouter ();
4249const toast = useToast ();
4350const { options } = useCodeStore ();
4451
4552// Store
4653const { getProject } = storeToRefs (projectStore );
54+ const { getEnquiry } = storeToRefs (enquiryStore );
4755
4856// State
57+ const createdByFullNames: Ref <Record <string , string >> = ref ({});
4958const formRef: Ref <InstanceType <typeof Form > | null > = ref (null );
5059const initialFormValues: Ref <any | undefined > = ref (undefined );
51- const visible = defineModel <boolean >(' visible' );
5260const shownToProponent: Ref <boolean > = ref (false );
53- const createdByFullNames : Ref < Record < string , string >> = ref ({} );
61+ const visible = defineModel < boolean >( ' visible ' );
5462
5563// Injections
5664const projectRouteName = inject (projectRouteNameKey );
@@ -61,12 +69,7 @@ const formSchema = object({
6169 .nullable ()
6270 .when (' type' , {
6371 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- ),
72+ then : (schema ) => schema .required (t (' note.noteForm.bfDateReqd' )),
7073 otherwise : (schema ) => schema .nullable ()
7174 })
7275 .label (' Bring forward date' ),
@@ -79,25 +82,37 @@ const formSchema = object({
7982 .label (' Bring forward state' ),
8083 note: string ().label (' Note' ),
8184 type: string ().oneOf (NOTE_TYPE_LIST ).label (' Note type' ),
82- title: string ().required ().max (255 , ' Title too long' ).label (' Title' )
85+ title: string ().required ().max (255 , ' Title too long' ).label (' Title' ),
86+ escalationType: mixed ()
87+ .when ([' escalateToSupervisor' , ' escalateToDirector' ], {
88+ is : (escalateToSupervisor : boolean , escalateToDirector : boolean ) => escalateToSupervisor || escalateToDirector ,
89+ then : (schema ) => schema .required (t (' note.noteForm.escalationTypeReqd' )),
90+ otherwise : (schema ) => schema .nullable ()
91+ })
92+ .label (' Escalation type' )
8393});
8494
8595function initializeFormValues() {
8696 if (noteHistory ) {
8797 initialFormValues .value = {
88- activityId: noteHistory ? .activityId ,
98+ activityId: noteHistory .activityId ,
8999 bringForwardDate: noteHistory ?.bringForwardDate ? new Date (noteHistory .bringForwardDate ) : null ,
90100 bringForwardState: noteHistory ?.bringForwardState ?? null ,
91101 escalateToSupervisor: noteHistory ?.escalateToSupervisor ,
92102 escalateToDirector: noteHistory ?.escalateToDirector ,
93103 escalationType: noteHistory ?.escalationType ,
94- noteHistoryId: noteHistory ? .noteHistoryId ,
95- type: noteHistory ? .type ?? NoteType . GENERAL ,
96- title: noteHistory ? .title
104+ noteHistoryId: noteHistory .noteHistoryId ,
105+ type: noteHistory .type ,
106+ title: noteHistory .title
97107 };
98108 shownToProponent .value = noteHistory .shownToProponent ;
109+ } else {
110+ initialFormValues .value = {
111+ type: NoteType .GENERAL
112+ };
99113 }
100114}
115+ // }
101116
102117function onInvalidSubmit(e : any ) {
103118 scrollToFirstError (e .errors );
@@ -106,20 +121,20 @@ function onInvalidSubmit(e: any) {
106121function onDelete() {
107122 if (noteHistory ) {
108123 confirmDialog .require ({
109- message: t (shownToProponent .value ? ' noteHistoryModal. deleteMessageIfShown' : ' noteHistoryModal .deleteMessage' ),
110- header: t (' noteHistoryModal .deleteHeader' ),
111- acceptLabel: t (' noteHistoryModal .confirm' ),
124+ message: t (shownToProponent .value ? ' note.noteForm. deleteMessageIfShown' : ' note.noteForm .deleteMessage' ),
125+ header: t (' note.noteForm .deleteHeader' ),
126+ acceptLabel: t (' note.noteForm .confirm' ),
112127 acceptClass: ' p-button-danger' ,
113- rejectLabel: t (' noteHistoryModal .cancel' ),
128+ rejectLabel: t (' note.noteForm .cancel' ),
114129 rejectProps: { outlined: true },
115130 accept : () => {
116131 noteHistoryService
117132 .deleteNoteHistory (noteHistory ?.noteHistoryId as string )
118133 .then (() => {
119- toast .success (t (' noteHistoryModal .noteDeleted' ));
120- toTheProject ();
134+ toast .success (t (' note.noteForm .noteDeleted' ));
135+ getProject . value ? toTheProject () : toTheEnquiry ();
121136 })
122- .catch ((e : any ) => toast .error (t (' noteHistoryModal .noteDeleteFailed' ), e .message ));
137+ .catch ((e : any ) => toast .error (t (' note.noteForm .noteDeleteFailed' ), e .message ));
123138 }
124139 });
125140 }
@@ -145,20 +160,20 @@ async function onSubmit(data: any) {
145160 if (! noteHistory ) {
146161 await noteHistoryService .createNoteHistory ({
147162 ... body ,
148- activityId: getProject .value ?.activityId ,
163+ activityId: getProject .value ?.activityId || getEnquiry . value ?. activityId ,
149164 note: data .note
150165 });
151166 } else {
152167 await noteHistoryService .updateNoteHistory (data .noteHistoryId , {
153168 ... body ,
154- activityId: getProject .value ?.activityId ,
169+ activityId: getProject .value ?.activityId || getEnquiry . value ?. activityId ,
155170 note: data .note
156171 });
157172 }
158- toast .success (t (' noteHistoryModal .noteSaved' ));
159- toTheProject ();
173+ toast .success (t (' note.noteForm .noteSaved' ));
174+ getProject . value ? toTheProject () : toTheEnquiry ();
160175 } catch (e : any ) {
161- toast .error (t (' noteHistoryModal .noteSaveFailed' ), e .message );
176+ toast .error (t (' note.noteForm .noteSaveFailed' ), e .message );
162177 } finally {
163178 visible .value = false ;
164179 }
@@ -167,6 +182,7 @@ async function onSubmit(data: any) {
167182function onTypeChange(e : SelectChangeEvent ) {
168183 if (e .value === NoteType .BRING_FORWARD ) {
169184 formRef .value ?.setFieldValue (' bringForwardState' , BringForwardType .UNRESOLVED );
185+ shownToProponent .value = false ;
170186 }
171187}
172188
@@ -183,7 +199,17 @@ function toTheProject() {
183199 name: projectRouteName ?.value ,
184200 params: { projectId: getProject .value ?.projectId },
185201 query: {
186- initialTab: ' 3'
202+ initialTab: NOTES_TAB_INDEX .SUBMISSION
203+ }
204+ });
205+ }
206+
207+ function toTheEnquiry() {
208+ router .push ({
209+ name: projectRouteName ?.value ,
210+ params: { enquiryId: getEnquiry .value ?.enquiryId },
211+ query: {
212+ initialTab: NOTES_TAB_INDEX .ENQUIRY
187213 }
188214 });
189215}
@@ -199,13 +225,13 @@ onBeforeMount(async () => {
199225<template >
200226 <div class =" flex flex-row gap-x-3 my-4" >
201227 <div class =" flex flex-row gap-x-1" >
202- <span class =" text-[var(--p-bcblue-900)]" >{{ t('noteHistoryModal .created') }}:</span >
228+ <span class =" text-[var(--p-bcblue-900)]" >{{ t('note.noteForm .created') }}:</span >
203229 <span >
204230 {{ formatDate(noteHistory?.createdAt || new Date().toISOString()) }}
205231 </span >
206232 </div >
207233 <div class =" flex flex-row gap-x-1" >
208- <span class =" text-[var(--p-bcblue-900)]" >{{ t('noteHistoryModal .lastUpdated') }}:</span >
234+ <span class =" text-[var(--p-bcblue-900)]" >{{ t('note.noteForm .lastUpdated') }}:</span >
209235 <span >{{ formatDate(noteHistory?.updatedAt) }}</span >
210236 </div >
211237 </div >
@@ -236,18 +262,21 @@ onBeforeMount(async () => {
236262 name="type"
237263 label="Note type"
238264 :options =" NOTE_TYPE_LIST "
265+ :disabled =" ! editable "
239266 @on-change =" onTypeChange "
240267 />
241268 <InputText
242269 class="w-1/2"
243270 name="title"
244271 label="Note title"
272+ :disabled =" ! editable "
245273 />
246274 </div >
247275
248276 <TextArea
249277 name="note"
250278 label="Note"
279+ :disabled =" ! editable "
251280 />
252281 </div >
253282
@@ -259,12 +288,13 @@ onBeforeMount(async () => {
259288 v-if =" values.type === NoteType.GENERAL"
260289 class =" flex flex-col gap-y-4"
261290 >
262- <span class =" font-bold" >{{ t('noteHistoryModal .showProponent') }}</span >
291+ <span class =" font-bold" >{{ t('note.noteForm .showProponent') }}</span >
263292 <ToggleSwitch
264293 v-model =" shownToProponent "
265294 class="mr-1"
266295 name="shownToProponent"
267- :label =" t (' noteHistoryModal.showProponent' )"
296+ :label =" t (' note.noteForm.showProponent' )"
297+ :disabled =" ! editable "
268298 />
269299 </div >
270300
@@ -275,20 +305,23 @@ onBeforeMount(async () => {
275305 <Checkbox
276306 v-if =" authzStore .isInGroup ([GroupName .NAVIGATOR , GroupName .NAVIGATOR_READ_ONLY ])"
277307 name="escalateToSupervisor"
278- :label =" t (' noteHistoryModal .escalateToSupervisor' )"
308+ :label =" t (' note.noteForm .escalateToSupervisor' )"
279309 :bold =" false "
310+ :disabled =" ! editable "
280311 />
281312 <Checkbox
282313 v-if =" authzStore .isInGroup ([GroupName .ADMIN , GroupName .DEVELOPER , GroupName .SUPERVISOR ])"
283314 name="escalateToDirector"
284- :label =" t (' noteHistoryModal .escalateToDirector' )"
315+ :label =" t (' note.noteForm .escalateToDirector' )"
285316 :bold =" false "
317+ :disabled =" ! editable "
286318 />
287319 <DatePicker
288320 v-if =" values .type === NoteType .BRING_FORWARD "
289321 class="my-2"
290322 name="bringForwardDate"
291323 label="Bring forward date"
324+ :disabled =" ! editable "
292325 />
293326 <div
294327 v-if =" values.escalateToSupervisor || values.escalateToDirector"
@@ -300,12 +333,14 @@ onBeforeMount(async () => {
300333 option-label="label"
301334 option-value="value"
302335 :options =" options .EscalationType "
336+ :disabled =" ! editable "
303337 />
304338 </div >
305339 <Select
306340 name="bringForwardState"
307341 label="Bring forward state"
308342 :options =" BRING_FORWARD_TYPE_LIST "
343+ :disabled =" ! editable "
309344 />
310345 </div >
311346 </div >
@@ -321,14 +356,15 @@ onBeforeMount(async () => {
321356 label="Save"
322357 type="submit"
323358 icon="pi pi-check"
359+ :disabled =" ! editable "
324360 />
325361 <Button
326362 class="p-button-outlined mr-2"
327363 label="Cancel"
328364 icon="pi pi-times"
329365 @click ="
330366 () => {
331- toTheProject ();
367+ getProject ? toTheProject () : toTheEnquiry ();
332368 }
333369 "
334370 />
@@ -341,6 +377,7 @@ onBeforeMount(async () => {
341377 class="p-button-outlined p-button-danger mr-2"
342378 label="Delete"
343379 icon="pi pi-trash"
380+ :disabled =" ! editable "
344381 @click =" onDelete "
345382 />
346383 </div >
0 commit comments