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

Adds support for searching user type in user creation form #7332

Closed
wants to merge 9 commits into from
52 changes: 32 additions & 20 deletions src/Components/Users/UserAdd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import routes from "../../Redux/api";
import request from "../../Utils/request/request";
import useQuery from "../../Utils/request/useQuery";
import CareIcon from "../../CAREUI/icons/CareIcon";
import AutocompleteFormField from "../Form/FormFields/Autocomplete";

const Loading = lazy(() => import("../Common/Loading"));

Expand Down Expand Up @@ -266,6 +267,17 @@ export const UserAdd = (props: UserProps) => {
},
});

const { loading: isStateLoading } = useQuery(routes.statesList, {
onResponse: (result) => {
if (!result || !result.res || !result.data) return;
if (userIndex <= USER_TYPES.indexOf("StateAdmin")) {
setStates([authUser.state_object!]);
} else {
setStates(result.data.results);
}
},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
onResponse: (result) => {
if (!result || !result.res || !result.data) return;
if (userIndex <= USER_TYPES.indexOf("StateAdmin")) {
setStates([authUser.state_object!]);
} else {
setStates(result.data.results);
}
},
onResponse: ({ data }) => {
if (!data) {
return;
}
if (userIndex <= USER_TYPES.indexOf("StateAdmin")) {
setStates([authUser.state_object!]);
} else {
setStates(data.results);
}
},

});

const { loading: isLocalbodyLoading } = useQuery(
routes.getAllLocalBodyByDistrict,
{
Expand All @@ -282,17 +294,6 @@ export const UserAdd = (props: UserProps) => {
}
);

const { loading: isStateLoading } = useQuery(routes.statesList, {
onResponse: (result) => {
if (!result || !result.res || !result.data) return;
if (userIndex <= USER_TYPES.indexOf("StateAdmin")) {
setStates([authUser.state_object!]);
} else {
setStates(result.data.results);
}
},
});

const handleDateChange = (e: FieldChangeEvent<Date>) => {
if (dayjs(e.value).isValid()) {
dispatch({
Expand Down Expand Up @@ -326,7 +327,7 @@ export const UserAdd = (props: UserProps) => {

const setFacility = (selected: FacilityModel | FacilityModel[] | null) => {
setSelectedFacility(selected as FacilityModel[]);
const form = { ...state.form };
const form: any = { ...state.form };
Copy link
Member

Choose a reason for hiding this comment

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

Casting to any not allowed.

Suggested change
const form: any = { ...state.form };
const form = { ...state.form };

form.facilities = selected
? (selected as FacilityModel[]).map((i) => i.id ?? -1)
: [];
Expand Down Expand Up @@ -583,10 +584,6 @@ export const UserAdd = (props: UserProps) => {
}
};

if (isLoading) {
return <Loading />;
}

const field = (name: string) => {
return {
id: name,
Expand All @@ -597,14 +594,18 @@ export const UserAdd = (props: UserProps) => {
};
};

if (isLoading) {
return <Loading />;
}

return (
<Page
title={headerText}
options={
<Link
href="https://school.coronasafe.network/targets/12953"
href="https://school.coronasafe.network/targets/12953 "
Copy link
Member

Choose a reason for hiding this comment

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

Why was this changed?

Suggested change
href="https://school.coronasafe.network/targets/12953 "
href="https://school.coronasafe.network/targets/12953"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While saving the file extra space removed.
Is this making any conflict?

className="inline-block rounded border border-gray-600 bg-gray-50 px-4 py-2 text-gray-600 transition hover:bg-gray-100"
target="_blank"
target="_blank "
Copy link
Member

Choose a reason for hiding this comment

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

Why was this changed?

Suggested change
target="_blank "
target="_blank"

>
<CareIcon icon="l-info-circle" className="text-lg" /> &nbsp;Need Help?
</Link>
Expand All @@ -631,15 +632,26 @@ export const UserAdd = (props: UserProps) => {
showAll={false}
/>
</div>
<SelectFormField

{/* <SelectFormField
Copy link
Member

Choose a reason for hiding this comment

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

You can remove this instead of commenting it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was checking the everything was working properly I will remove and make new commit.

{...field("user_type")}
required
label="User Type"
options={userTypes}
optionLabel={(o) => o.role + (o.readOnly ? " (Read Only)" : "")}
optionValue={(o) => o.id}
/>
/> */}

<AutocompleteFormField
{...field("user_type")}
label="User Type"
placeholder="Search for a user type..."
// value={userTypes}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// value={userTypes}

options={userTypes ?? []}
optionLabel={(o) => o.role + (o.readOnly ? " (Read Only)" : "")}
optionValue={(o) => o.id}
required
/>
{state.form.user_type === "Doctor" && (
<>
<TextFormField
Expand Down
Loading