Skip to content

Commit a24e3ee

Browse files
committed
minor fix: autofill assessing staff to current auth user
1 parent 6d75bfc commit a24e3ee

1 file changed

Lines changed: 25 additions & 30 deletions

File tree

  • icv/src/app/(no-nav)/intake/background/family/services/confirmation

icv/src/app/(no-nav)/intake/background/family/services/confirmation/page.tsx

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ import { useForm } from 'react-hook-form'
3030
import { TypeOf } from 'zod'
3131
import { useIntakeFormStore } from '../../../../../../_lib/useIntakeFormStore'
3232

33-
type CaseManagerOption = {
34-
label: string
35-
value: string
36-
}
37-
3833
const Page = () => {
3934
const { form: loadedForm, updateForm } = useIntakeFormStore()
4035
type ConfirmType = TypeOf<typeof ConfirmationSchema>
@@ -54,31 +49,23 @@ const Page = () => {
5449
const [spouseInfo, setSpouseInfo] = useState<NewClient>({} as NewClient)
5550
const [users, setUsers] = useState<Users[]>([])
5651

57-
const caseManagerOptions: CaseManagerOption[] = users
52+
const caseManagerOptions = users
5853
.map((staff) => ({
5954
label: staff.name,
6055
value: staff.uid ?? staff.id ?? '',
6156
}))
6257
.filter((option) => option.value)
6358

64-
const defaultCaseManagerValue =
65-
loadedForm.caseManager ?? user?.uid ?? user?.displayName ?? ''
66-
6759
const selectedCaseManager =
6860
caseManagerOptions.find(
6961
(option) =>
70-
option.value === defaultCaseManagerValue ||
71-
option.label === defaultCaseManagerValue,
72-
) ??
73-
(defaultCaseManagerValue
74-
? {
75-
label:
76-
caseManagerOptions.find(
77-
(option) => option.value === defaultCaseManagerValue,
78-
)?.label ?? user?.displayName ?? defaultCaseManagerValue,
79-
value: defaultCaseManagerValue,
80-
}
81-
: undefined)
62+
option.value === loadedForm.caseManager ||
63+
option.label === loadedForm.caseManager,
64+
)?.label ??
65+
user?.displayName ??
66+
''
67+
68+
const caseManagerLabels = caseManagerOptions.map((option) => option.label)
8269

8370
useEffect(() => {
8471
if (loadedForm.associatedSpouseID) {
@@ -96,8 +83,12 @@ const Page = () => {
9683
)
9784
}, [])
9885

99-
const handleCaseManagerChange = (value: CaseManagerOption | null) => {
100-
updateForm({ caseManager: value?.value ?? '' })
86+
const handleCaseManagerChange = (value: string | null) => {
87+
const selectedOption = caseManagerOptions.find(
88+
(option) => option.label === value,
89+
)
90+
91+
updateForm({ caseManager: selectedOption?.value ?? value ?? '' })
10192
}
10293

10394
// wait until after render (in case rendering occurs before user is async loaded)
@@ -152,20 +143,24 @@ const Page = () => {
152143
onChange={(_, newValue) =>
153144
handleCaseManagerChange(newValue)
154145
}
155-
options={caseManagerOptions}
156-
getOptionLabel={(option) => option.label}
157-
isOptionEqualToValue={(option, value) =>
158-
option.value === value.value
146+
options={
147+
selectedCaseManager &&
148+
!caseManagerLabels.includes(
149+
selectedCaseManager,
150+
)
151+
? [
152+
selectedCaseManager,
153+
...caseManagerLabels,
154+
]
155+
: caseManagerLabels
159156
}
160157
filterOptions={(options, state) => {
161158
const input = state.inputValue
162159
.trim()
163160
.toLowerCase()
164161
if (!input) return options
165162
return options.filter((option) =>
166-
option.label
167-
.toLowerCase()
168-
.includes(input),
163+
option.toLowerCase().includes(input),
169164
)
170165
}}
171166
renderInput={(params) => (

0 commit comments

Comments
 (0)