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

Update weekly_working_hours to allow null value #7015

Merged
merged 1 commit into from
Jan 12, 2024
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
23 changes: 12 additions & 11 deletions src/Components/Users/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type EditForm = {
doctor_qualification: string | undefined;
doctor_experience_commenced_on: number | string | undefined;
doctor_medical_council_registration: string | undefined;
weekly_working_hours: string | undefined;
weekly_working_hours: string | null;
};
type ErrorForm = {
firstName: string;
Expand Down Expand Up @@ -253,13 +253,11 @@ export default function UserProfile() {
}
return;
case "weekly_working_hours":
if (!states.form[field]) {
errors[field] = "This field is required";
invalidForm = true;
} else if (
Number(states.form[field]) < 0 ||
Number(states.form[field]) > 168 ||
!/^\d+$/.test(states.form[field] ?? "")
if (
states.form[field] &&
(Number(states.form[field]) < 0 ||
Number(states.form[field]) > 168 ||
!/^\d+$/.test(states.form[field] ?? ""))
) {
errors[field] =
"Average weekly working hours must be a number between 0 and 168";
Expand Down Expand Up @@ -331,7 +329,11 @@ export default function UserProfile() {
states.form.user_type === "Doctor"
? states.form.doctor_medical_council_registration
: undefined,
weekly_working_hours: states.form.weekly_working_hours,
weekly_working_hours:
states.form.weekly_working_hours &&
states.form.weekly_working_hours !== ""
? states.form.weekly_working_hours
: null,
};
const { res } = await request(routes.partialUpdateUser, {
pathParams: { username: authUser.username },
Expand Down Expand Up @@ -588,7 +590,7 @@ export default function UserProfile() {
Average weekly working hours
</dt>
<dd className="mt-1 text-sm leading-5 text-gray-900">
{userData?.weekly_working_hours || "-"}
{userData?.weekly_working_hours ?? "-"}
</dd>
</div>
<div
Expand Down Expand Up @@ -707,7 +709,6 @@ export default function UserProfile() {
)}
<TextFormField
{...fieldProps("weekly_working_hours")}
required
label="Average weekly working hours"
className="col-span-6 sm:col-span-3"
type="number"
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Users/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type UserModel = UserBareMinimum & {
doctor_qualification?: string;
doctor_experience_commenced_on?: string;
doctor_medical_council_registration?: string;
weekly_working_hours?: string;
weekly_working_hours?: string | null;
};

export interface SkillObjectModel {
Expand Down
Loading