Fix: Add District to the Accompanying details section #342#346
Conversation
nadavosa
left a comment
There was a problem hiding this comment.
The field wiring looks correct in display, edit, and schema — good pattern, consistent with appointmentAddress.
One bug in helpers.ts: the initial value is hardcoded to "" instead of reading from details:
// current (bug — always empty on load)
appointmentDistrict: "",
// should be
appointmentDistrict: details?.appointmentDistrict || "",Without this, existing district values stored in the DB will never be shown when the section loads.
|
|
|
Updated |
|
Before this gets merged, please run |
|
Everything is fine |
|
The district field should use the API-driven dropdown (same pattern as the RAC section in #377) rather than a free-text input. Here are the exact changes needed:
accompanyingDetails: {
appointmentAddress?: string;
appointmentDistrict?: number; // add this
appointmentDate?: string;
...
export const getInitialFormValues = (
details: ApiOpportunityAccompanyingDetails | undefined,
districtIdToTitle: Record<number, string> = {}, // add this param
): AccompanyingDetailsFormData => {
const rawDistrict = (details as ApiOpportunityAccompanyingDetails & { appointmentDistrict?: string | number })
?.appointmentDistrict;
const appointmentDistrict = districtIdToTitle[Number(rawDistrict)] || "";
return {
appointmentAddress: details?.appointmentAddress || "",
appointmentDistrict,
appointmentDate: parseDate(details?.appointmentDate),
appointmentTime: parseTime(details?.appointmentTime),
refugeeNumber: details?.refugeeNumber || "",
refugeeName: details?.refugeeName || "",
languageToTranslate: details?.languageToTranslate?.toString() ?? "",
};
};
// add imports at top
import { useApiDistricts, useApiLanguages } from "@/components/Dashboard/Profile/sections/VolunteerProfile/hooks";
import { createMapping } from "@/components/Dashboard/Profile/sections/VolunteerProfile/mappingUtils";
// inside component, after useApiLanguages:
const { data: apiDistricts = [] } = useApiDistricts();
const districtMapping = useMemo(() => createMapping(apiDistricts), [apiDistricts]);
const districtOptions = apiDistricts.map((d) => d.title);
// pass mapping to getInitialFormValues (both the initial call and the reset in useEffect):
const initialFormValues = getInitialFormValues(opportunity.accompanyingDetails, districtMapping.idToTitle);
// ...
reset(getInitialFormValues(opportunity.accompanyingDetails, districtMapping.idToTitle));
// in onSubmit, add district ID:
accompanyingDetails: {
appointmentAddress: values.appointmentAddress,
...(districtMapping.titleToId[values.appointmentDistrict || ""] !== undefined && {
appointmentDistrict: districtMapping.titleToId[values.appointmentDistrict || ""],
}),
// ... rest unchanged
// pass districtOptions to AccompanyingDetailsEdit:
<AccompanyingDetailsEdit
districtOptions={districtOptions}
// ... rest unchanged
// add to Props type:
districtOptions: string[];
// add to destructured params:
export const AccompanyingDetailsEdit = ({ ..., districtOptions, ... }) => {
// change the district EditableField:
<EditableField
mode="edit"
type="radio-list" // was "text"
label={t("dashboard.opportunityProfile.accompanyingDetails.appointmentDistrict")}
value={field.value || ""}
setValue={field.onChange}
options={districtOptions} // add this
errorMessage={errors.appointmentDistrict?.message}
/> |
|
Updated |
Fix: Add District to the Accompanying details section need4deed-org#342
…rg#342 Updated: Add District to the Accompanying details section
a949d57 to
d50a5ca
Compare
|
Updated |
nadavosa
left a comment
There was a problem hiding this comment.
Both fixes applied:
getInitialFormValuesnow readsdetails?.appointmentDistrict || ""— existing values will load correctly- District is sent in the mutation payload
- Display label resolved via
districtKeyToLabel
FE is complete. As noted before, merge is contingent on the BE actually persisting this field.
Fix: Add District to the Accompanying details section #342
Description
Adds the District field to the Accompanying Details section on the frontend. Backend support is still needed to persist the value.
Related Issues
Closes #342
Changes
appointmentDistrictfield to the accompanying details schemaScreenshots / Demos
Checklist