Skip to content
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

Fix facilities dropdown #6030

Merged
merged 4 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions frontend/src/app/Settings/Facility/FacilityForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { deviceRequiredErrMsg, facilityInfoErrMsgs } from "./constants";

export type FacilityFormData = {
facility: {
id?: string;
name: string;
phone: string;
email: string | null;
Expand Down Expand Up @@ -114,7 +115,7 @@ const FacilityForm: React.FC<Props> = (props) => {
getValues,
getFieldState,
clearErrors,
formState: { errors, isSubmitting, isDirty },
formState: { errors, isDirty },
} = useForm({
defaultValues: getDefaultValues(facility),
});
Expand Down Expand Up @@ -362,7 +363,7 @@ const FacilityForm: React.FC<Props> = (props) => {
className="margin-right-0 margin-top-05"
type="submit"
label="Save changes"
disabled={isSubmitting || !isDirty}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this wasn't actually setting the save button to be disabled when we click the "Save changes" button. isSubmitted would do that but there's an issue if you back out of the address confirmation modal -- it won't reactivate the "Save changes" button so I opted to remove this.

disabled={!isDirty}
/>
</div>
</div>
Expand Down Expand Up @@ -412,7 +413,7 @@ const FacilityForm: React.FC<Props> = (props) => {
className="margin-right-0"
type="submit"
label="Save changes"
disabled={isSubmitting || !isDirty}
disabled={!isDirty}
/>
</div>
<AddressConfirmationModal
Expand Down
20 changes: 11 additions & 9 deletions frontend/src/app/Settings/Facility/FacilityFormContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const FacilityFormContainer: any = (props: Props) => {
FacilityFormData | undefined
>(undefined);
const dispatch = useDispatch();

if (loading) {
return <p> Loading... </p>;
}
Expand All @@ -46,8 +47,15 @@ const FacilityFormContainer: any = (props: Props) => {
if (!data) {
return <p>Error: facility not found</p>;
}

if (saveSuccess) {
dispatch(updateFacility(facilityData));
dispatch(updateFacility(facilityData?.facility));

showSuccess(
"The settings for the facility have been updated",
"Updated Facility"
);

if (props.newOrg) {
window.location.pathname = process.env.PUBLIC_URL || "";
}
Expand Down Expand Up @@ -98,15 +106,9 @@ const FacilityFormContainer: any = (props: Props) => {
(response) => response?.data?.addFacility?.id
);

setFacilityData(() => ({
...facilityData,
id: savedFacilityId as string,
}));
facilityData.facility.id = savedFacilityId;

showSuccess(
"The settings for the facility have been updated",
"Updated Facility"
);
setFacilityData(facilityData);
updateSaveSuccess(true);
};

Expand Down