diff --git a/app/(authenticated)/calendar/[eventID]/AddEditSignUpSheetForm.tsx b/app/(authenticated)/calendar/[eventID]/AddEditSignUpSheetForm.tsx index fb865f08..bb6a4be1 100644 --- a/app/(authenticated)/calendar/[eventID]/AddEditSignUpSheetForm.tsx +++ b/app/(authenticated)/calendar/[eventID]/AddEditSignUpSheetForm.tsx @@ -148,6 +148,9 @@ function CrewPositionField(props: { parentName: string }) { const selectController = useController({ name: `${props.parentName}.position_id`, }); + // Track the initial selected ID so that, if it's a custom field (but one that existed + // before), we can still display the correct value. + const [initialSelectedID] = useState(() => selectController.field.value); const customController = useController({ name: `${props.parentName}.custom_position_name`, }); @@ -162,14 +165,20 @@ function CrewPositionField(props: { parentName: string }) { return [selectController.field.value.toString(10), false]; }, [selectController.field.value, customController.field.value]); + const filteredProcessedVals = useMemo( + () => + vals + .filter((x) => !x.is_custom || x.position_id === initialSelectedID) + .map((v) => ({ + label: v.name, + value: v.position_id.toString(10), + })), + [vals, initialSelectedID], + ); + return ( ({ - label: val.name, - value: val.position_id.toString(10), - })), - ].filter(Boolean)} + data={filteredProcessedVals} value={value} isCustomValue={isCustom} onChange={(newValue, isNew) => { diff --git a/app/(authenticated)/calendar/[eventID]/page.tsx b/app/(authenticated)/calendar/[eventID]/page.tsx index eaca27ad..462ae136 100644 --- a/app/(authenticated)/calendar/[eventID]/page.tsx +++ b/app/(authenticated)/calendar/[eventID]/page.tsx @@ -12,7 +12,7 @@ import { EventObjectType, getEvent } from "@/features/calendar/events"; import { canManage, canManageAnySignupSheet, - getAllNonCustomCrewPositions, + getAllCrewPositions, } from "@/features/calendar"; import { CrewPositionsProvider, @@ -90,7 +90,7 @@ async function ShowView({ // TODO(WEB-40): this pre-loads quite a bit of information that we don't actually need until you go to edit a sheet. // Would be better to either load it on-demand dynamically, or move the edit view to a sub-page. const [positions, members] = await Promise.all([ - getAllNonCustomCrewPositions(), + getAllCrewPositions(), getAllUsers(), ]); return ( diff --git a/features/calendar/crew_positions.ts b/features/calendar/crew_positions.ts index aa538123..fc3f3dae 100644 --- a/features/calendar/crew_positions.ts +++ b/features/calendar/crew_positions.ts @@ -7,15 +7,13 @@ export interface CrewPositionType { admin: boolean; brief_description: string; full_description: string; + is_custom: boolean; } -export function getAllNonCustomCrewPositions(): Promise { +export function getAllCrewPositions(): Promise { return prisma.position.findMany({ orderBy: { position_id: "asc", }, - where: { - is_custom: false, - }, }); }