107
107
</div >
108
108
</Transition >
109
109
<div
110
- v-if =" healthcareProfessionalsStore.healthcareProfessionalSectionFields.names"
110
+ v-if =" moderationScreenStore.editHealthcareProfessionalScreenIsActive()
111
+ && healthcareProfessionalsStore.healthcareProfessionalSectionFields.names"
111
112
class =" flex flex-col"
112
113
>
113
114
<div
124
125
/>
125
126
</div >
126
127
</div >
128
+ <div
129
+ v-if =" moderationScreenStore.createHealthcareProfessionalScreenIsActive()
130
+ && healthcareProfessionalsStore.createHealthcareProfessionalInput.names"
131
+ class =" flex flex-col"
132
+ >
133
+ <div
134
+ v-for =" (nameLocale, index) in healthcareProfessionalsStore.createHealthcareProfessionalInput.names"
135
+ :key =" `${nameLocale.firstName}-${nameLocale.lastName}-${index}`"
136
+ @click =" () => setChosenLocaleNameInput(index)"
137
+ >
138
+ <ModDashboardHealthProfessionalCard
139
+ :healthcare-professional =" {} as HealthcareProfessional"
140
+ :healthcare-professional-name-by-locale =" nameLocale"
141
+ :chosen-locale-index =" index"
142
+ :is-editable =" editingLocaleName"
143
+ :set-is-editable-function =" setEditingLocaleName"
144
+ />
145
+ </div >
146
+ </div >
127
147
<button
128
148
type =" button"
129
149
data-testid =" mod-healthcare-add-name-button"
@@ -265,7 +285,14 @@ import ModSearchbar from './ModSearchBar.vue'
265
285
import { useHealthcareProfessionalsStore } from ' ~/stores/healthcareProfessionalsStore'
266
286
import { useFacilitiesStore } from ' ~/stores/facilitiesStore'
267
287
import { useLocaleStore } from ' ~/stores/localeStore'
268
- import { Insurance , Locale , Degree , Specialty , type LocalizedNameInput , type Facility } from ' ~/typedefs/gqlTypes'
288
+ import { useModerationScreenStore } from ' ~/stores/moderationScreenStore'
289
+ import { Insurance ,
290
+ Locale ,
291
+ Degree ,
292
+ Specialty ,
293
+ type LocalizedNameInput ,
294
+ type Facility ,
295
+ type HealthcareProfessional } from ' ~/typedefs/gqlTypes'
269
296
import { useI18n } from ' #imports'
270
297
271
298
let toast: ToastInterface
@@ -277,6 +304,7 @@ const { t } = useI18n()
277
304
const loadingStore = useLoadingStore ()
278
305
loadingStore .setIsLoading (true )
279
306
307
+ const moderationScreenStore = useModerationScreenStore ()
280
308
const localesStore = useLocaleStore ()
281
309
const healthcareProfessionalsStore = useHealthcareProfessionalsStore ()
282
310
const facilitiesStore = useFacilitiesStore ()
@@ -361,19 +389,35 @@ const setChosenLocaleNameInput = (index: number) => {
361
389
362
390
// This will keep track of the healthcare professional to not lose it but we can swap it later with the chosen one
363
391
const tempToHoldZeroIndexedHealthcareProfessionalToSwap
364
- = healthcareProfessionalsStore .healthcareProfessionalSectionFields .names [0 ]
392
+ = moderationScreenStore .editHealthcareProfessionalScreenIsActive ()
393
+ ? healthcareProfessionalsStore .healthcareProfessionalSectionFields .names [0 ]
394
+ : healthcareProfessionalsStore .createHealthcareProfessionalInput .names [0 ]
365
395
366
396
// This finds the chosen healthcare professional to edit
367
397
chosenHealthcareProfessionalToEdit .value
368
- = healthcareProfessionalsStore .healthcareProfessionalSectionFields .names .find ((_ , index ) => index === chosenLocaleIndex .value )
398
+ = moderationScreenStore .editHealthcareProfessionalScreenIsActive ()
399
+ ? healthcareProfessionalsStore .healthcareProfessionalSectionFields
400
+ .names .find ((_ , index ) => index === chosenLocaleIndex .value )
401
+ : healthcareProfessionalsStore .createHealthcareProfessionalInput
402
+ .names .find ((_ , index ) => index === chosenLocaleIndex .value )
369
403
370
404
if (chosenHealthcareProfessionalToEdit .value ) {
371
405
// Set the chosen healthcare professional name to move it closer to the input
372
- healthcareProfessionalsStore .healthcareProfessionalSectionFields .names [0 ]
406
+ if (moderationScreenStore .editHealthcareProfessionalScreenIsActive ()) {
407
+ healthcareProfessionalsStore .healthcareProfessionalSectionFields .names [0 ]
373
408
= chosenHealthcareProfessionalToEdit .value
374
- // Put the temp one in the index where the old locale name was
375
- healthcareProfessionalsStore .healthcareProfessionalSectionFields .names [chosenLocaleIndex .value ]
376
- = tempToHoldZeroIndexedHealthcareProfessionalToSwap
409
+ // Put the temp one in the index where the old locale name was
410
+ healthcareProfessionalsStore .healthcareProfessionalSectionFields .names [chosenLocaleIndex .value ]
411
+ = tempToHoldZeroIndexedHealthcareProfessionalToSwap
412
+ }
413
+
414
+ if (moderationScreenStore .createHealthcareProfessionalScreenIsActive ()) {
415
+ healthcareProfessionalsStore .createHealthcareProfessionalInput .names [0 ]
416
+ = chosenHealthcareProfessionalToEdit .value
417
+ // Put the temp one in the index where the old locale name was
418
+ healthcareProfessionalsStore .createHealthcareProfessionalInput .names [chosenLocaleIndex .value ]
419
+ = tempToHoldZeroIndexedHealthcareProfessionalToSwap
420
+ }
377
421
// Autofill with the chosen healthcare professional locale name]
378
422
autofillNameLocaleInputWithChosenHealthcareProfessional (chosenHealthcareProfessionalToEdit .value )
379
423
// Set the chosenLocaleIndex to 0 so the correct pencil is showing
@@ -426,13 +470,21 @@ const handleUpdateExistingName = () => {
426
470
}
427
471
428
472
const handleDeleteExistingName = () => {
429
- if (healthcareProfessionalsStore .healthcareProfessionalSectionFields .names .length <= 1 ) {
473
+ if (healthcareProfessionalsStore .healthcareProfessionalSectionFields .names .length <= 1
474
+ && moderationScreenStore .editHealthcareProfessionalScreenIsActive ()
475
+ ) {
430
476
toast .error (t (' modHealthcareProfessionalSection.oneNameNecessary' ))
431
477
return
432
478
}
433
- // Remove the first element safely since we reordered the one for deletion at 0
434
- healthcareProfessionalsStore .healthcareProfessionalSectionFields .names .shift ()
435
479
480
+ // Remove the first element safely since we reordered the one for deletion at 0
481
+ if (moderationScreenStore .editHealthcareProfessionalScreenIsActive ()) {
482
+ healthcareProfessionalsStore .healthcareProfessionalSectionFields .names .shift ()
483
+ }
484
+ // Remove the first element safely since we reordered the one for deletion at 0
485
+ if (moderationScreenStore .createHealthcareProfessionalScreenIsActive ()) {
486
+ healthcareProfessionalsStore .createHealthcareProfessionalInput .names .shift ()
487
+ }
436
488
setEditingLocaleName (false )
437
489
438
490
// Allows for the inputs to completely transition before resetting the fields
@@ -451,8 +503,7 @@ const handleAddLocalizedName = () => {
451
503
middleName: nameLocaleInputs .middleName
452
504
}
453
505
// Checks to keep user from adding a name with same locale instead of editing
454
- const existingNameForLocale = healthcareProfessionalsStore .healthcareProfessionalSectionFields .names
455
- .find (name => name .locale === nameLocaleInputs .locale )
506
+ const existingNameForLocale = checkIfHealthcareProfessionalHasAnExistingNameForLocale ()
456
507
457
508
// Displays message if user is trying to add a locale for name that exists and they aren't editing a healthcare professional
458
509
if (existingNameForLocale ) {
@@ -478,18 +529,40 @@ const handleAddLocalizedName = () => {
478
529
return
479
530
}
480
531
481
- if (nameLocaleInputs .firstName
482
- && nameLocaleInputs .lastName
483
- && nameLocaleInputs .firstName .length
484
- && nameLocaleInputs .lastName .length
485
- && healthcareProfessionalsStore .healthcareProfessionalSectionFields .names ) {
532
+ const checkValidityOfNameInputs
533
+ = nameLocaleInputs .firstName
534
+ && nameLocaleInputs .lastName
535
+ && nameLocaleInputs .firstName .length
536
+ && nameLocaleInputs .lastName .length
537
+
538
+ if (checkValidityOfNameInputs
539
+ && healthcareProfessionalsStore .healthcareProfessionalSectionFields .names
540
+ && moderationScreenStore .editHealthcareProfessionalScreenIsActive ()) {
486
541
healthcareProfessionalsStore .healthcareProfessionalSectionFields .names .push (localizedNameToAdd )
487
542
}
488
543
544
+ if (checkValidityOfNameInputs
545
+ && healthcareProfessionalsStore .createHealthcareProfessionalInput .names
546
+ && moderationScreenStore .createHealthcareProfessionalScreenIsActive ()) {
547
+ healthcareProfessionalsStore .createHealthcareProfessionalInput .names .push (localizedNameToAdd )
548
+ }
549
+
489
550
// Sets the chosen healthcare professional to undefined to reset
490
551
handleCloseAddingNewLocalizedName ()
491
552
}
492
553
554
+ function checkIfHealthcareProfessionalHasAnExistingNameForLocale() {
555
+ if (moderationScreenStore .editHealthcareProfessionalScreenIsActive ()) {
556
+ return healthcareProfessionalsStore .healthcareProfessionalSectionFields .names
557
+ .find (name => name .locale === nameLocaleInputs .locale )
558
+ }
559
+
560
+ if (moderationScreenStore .createHealthcareProfessionalScreenIsActive ()) {
561
+ return healthcareProfessionalsStore .createHealthcareProfessionalInput .names
562
+ .find (name => name .locale === nameLocaleInputs .locale )
563
+ }
564
+ }
565
+
493
566
const handleFacilitySearchInputChange = (filteredItems : Ref <Facility []>, inputValue : string ) => {
494
567
filteredItems .value = currentFacilities .filter (({ nameEn , nameJa , id }) => {
495
568
const isMatch
0 commit comments