-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[ENG-551] Replace all other usages of GovtOrgSelector with the new picker #16451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
fa9a2c1
d2d0c32
f7bd2e7
ca8e6ef
273ca03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,7 +45,7 @@ import { GENDERS, GENDER_TYPES, NAME_PREFIXES } from "@/common/constants"; | |
| import mutate from "@/Utils/request/mutate"; | ||
| import query from "@/Utils/request/query"; | ||
| import validators from "@/Utils/validators"; | ||
| import GovtOrganizationSelector from "@/pages/Organization/components/GovtOrganizationSelector"; | ||
| import GovtOrganizationPicker from "@/components/Organization/GovtOrganizationPicker"; | ||
| import { Organization } from "@/types/organization/organization"; | ||
| import organizationApi from "@/types/organization/organizationApi"; | ||
| import { UserCreate, UserReadMinimal, UserUpdate } from "@/types/user/user"; | ||
|
|
@@ -70,9 +70,10 @@ export default function UserForm({ | |
| const { t } = useTranslation(); | ||
| const isEditMode = !!existingUsername; | ||
| const queryClient = useQueryClient(); | ||
| const [selectedLevels, setSelectedLevels] = useState<Organization[]>([]); | ||
| const [selectedGeoOrg, setSelectedGeoOrg] = useState<Organization | null>( | ||
| null, | ||
| ); | ||
| const [isPasswordFieldFocused, setIsPasswordFieldFocused] = useState(false); | ||
|
|
||
| const roleOrgSchema = z.object({ | ||
| organization: z.string().min(1, t("select_role_organization")), | ||
| role: z.string().min(1, t("please_select_role")), | ||
|
|
@@ -377,16 +378,12 @@ export default function UserForm({ | |
| }); | ||
|
|
||
| useEffect(() => { | ||
| const levels: Organization[] = []; | ||
| if (org && org.org_type === "govt") levels.push(org); | ||
| setSelectedLevels(levels); | ||
| setSelectedGeoOrg(org && org.org_type === "govt" ? org : null); | ||
| }, [org, organizationId]); | ||
|
|
||
| useEffect(() => { | ||
| const levels: Organization[] = []; | ||
| if (isEditMode && userData?.geo_organization) { | ||
| levels.push(userData.geo_organization); | ||
| setSelectedLevels(levels); | ||
| setSelectedGeoOrg(userData.geo_organization); | ||
| } | ||
| }, [userData, isEditMode]); | ||
|
|
||
|
|
@@ -798,19 +795,20 @@ export default function UserForm({ | |
| <FormField | ||
| control={form.control} | ||
| name="geo_organization" | ||
| render={({ field }) => ( | ||
| render={({ field, fieldState }) => ( | ||
| <FormItem> | ||
| <FormControl> | ||
| <GovtOrganizationSelector | ||
| {...field} | ||
| value={form.watch("geo_organization")} | ||
| selected={selectedLevels} | ||
| onChange={(value) => | ||
| form.setValue("geo_organization", value, { | ||
| <GovtOrganizationPicker | ||
| ref={field.ref} | ||
| aria-invalid={!!fieldState.error} | ||
| requiredDepth={1} | ||
| value={selectedGeoOrg} | ||
| onChange={(organization) => { | ||
| setSelectedGeoOrg(organization); | ||
| form.setValue("geo_organization", organization?.id ?? "", { | ||
| shouldDirty: true, | ||
| }) | ||
| } | ||
| required={false} | ||
| }); | ||
|
Comment on lines
+804
to
+810
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sync preselected picker value into the form state in create mode. Line 805 renders Suggested fix useEffect(() => {
- setSelectedGeoOrg(org && org.org_type === "govt" ? org : null);
-}, [org, organizationId]);
+ const govtOrg = org && org.org_type === "govt" ? org : null;
+ setSelectedGeoOrg(govtOrg);
+ if (!isEditMode) {
+ form.setValue("geo_organization", govtOrg?.id ?? "", {
+ shouldDirty: false,
+ });
+ }
+}, [org, isEditMode, form]);🤖 Prompt for AI Agents |
||
| }} | ||
| /> | ||
| </FormControl> | ||
| <FormMessage /> | ||
|
|
||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.