Skip to content

Commit

Permalink
Update weekly_working_hours to allow null value
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashesh3 committed Jan 12, 2024
1 parent 0667894 commit 2353f3b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
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

0 comments on commit 2353f3b

Please sign in to comment.