Skip to content

Commit

Permalink
refactor: using datepicker for date of birth
Browse files Browse the repository at this point in the history
  • Loading branch information
ad956 committed Jun 15, 2024
1 parent 0782273 commit ff806ef
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions app/(pages)/patient/components/ProfileSettings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
"use client";

import { Patient } from "@/types";
import { Input, Button, Card, Avatar, Tooltip } from "@nextui-org/react";
import {
Input,
Button,
Card,
Avatar,
Tooltip,
DatePicker,
} from "@nextui-org/react";
import { CldUploadWidget } from "next-cloudinary";
import Image from "next/image";
import React, { type ChangeEvent, useRef, useState, useEffect } from "react";
import { AiTwotoneEye, AiOutlineEyeInvisible } from "react-icons/ai";
import toast, { Toaster } from "react-hot-toast";
import { DateValue, parseDate } from "@internationalized/date";

export default function ProfileSettings({ patient }: { patient: Patient }) {
const [isVisible, setIsVisible] = useState(true);
Expand All @@ -22,7 +30,7 @@ export default function ProfileSettings({ patient }: { patient: Patient }) {
const [password, setPassword] = useState("");
const [passwordError, setPasswordError] = useState(null || String);
const [profilePicture, setProfilePicture] = useState(patient.profile);
const [dob, setDob] = useState(patient.dob);
const [dob, setDob] = useState<DateValue>(parseDate(patient.dob));
const [contact, setContact] = useState(patient.contact);
const [gender, setGender] = useState(patient.gender);
const [address, setAddress] = useState({
Expand Down Expand Up @@ -202,7 +210,7 @@ export default function ProfileSettings({ patient }: { patient: Patient }) {
firstname: firstname !== patient.firstname ? firstname : undefined,
username: username !== patient.username ? username : undefined,
email: email !== patient.email ? email : undefined,
dob: dob !== patient.dob ? dob : undefined,
dob: dob.toString() !== patient.dob ? dob : undefined,
lastname: lastname !== patient.lastname ? lastname : undefined,
password: password !== "" ? password : undefined,
contact: contact !== patient.contact ? contact : undefined,
Expand Down Expand Up @@ -334,13 +342,21 @@ export default function ProfileSettings({ patient }: { patient: Patient }) {
ref={emailRef}
onBlur={() => showToast(emailRef)}
/>
<Input

<DatePicker
name="dob"
type="text"
variant="underlined"
label="DOB"
value={dob}
variant="underlined"
className="max-w-xs"
value={dob}
onChange={(val) => console.log(val)}
showMonthAndYearPickers
isInvalid
errorMessage={(value) => {
if (value.isInvalid) {
return "Please enter a valid date.";
}
}}
/>
</div>
<div className="flex flex-col w-full gap-5">
Expand Down

0 comments on commit ff806ef

Please sign in to comment.