Skip to content
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
3 changes: 2 additions & 1 deletion src/components/signup/formRow.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function FormRow({ label, type = "text", value, onChange, children, required = false }) {
export default function FormRow({ label, type = "text", value, onChange, children, required = false, ...rest }) {
return (
<div className="
flex items-center
Expand All @@ -25,6 +25,7 @@ export default function FormRow({ label, type = "text", value, onChange, childre
value={value}
onChange={onChange}
required={required}
{...rest}
className="
w-full h-11
bg-white/35 backdrop-blur-md
Expand Down
32 changes: 29 additions & 3 deletions src/pages/Login_Signup/signupPagePatient.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export default function SignupPagePatient() {
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);

// Date-of-birth bounds (recalculated at render time)
const today = new Date();
const dobMax = new Date(today);
dobMax.setDate(dobMax.getDate() - 1); // at least 1 day old
const dobMin = new Date(today);
dobMin.setFullYear(dobMin.getFullYear() - 110); // at most 110 years old
const toDateStr = (d) => d.toISOString().split("T")[0];

const handleSignup = async () => {
setError("");

Expand Down Expand Up @@ -57,6 +65,19 @@ export default function SignupPagePatient() {
return;
}

// Validate date of birth range
if (dateOfBirth) {
const dob = new Date(dateOfBirth);
if (dob > dobMax) {
setError("Date of birth must be at least 1 day in the past.");
return;
}
if (dob < dobMin) {
setError("Date of birth cannot be more than 110 years ago.");
return;
}
}

setLoading(true);
try {
const response = await fetch(`${API_BASE_URL}/api/auth/signup`, {
Expand Down Expand Up @@ -155,6 +176,8 @@ export default function SignupPagePatient() {
type="date"
value={dateOfBirth}
onChange={(e) => setDateOfBirth(e.target.value)}
min={toDateStr(dobMin)}
max={toDateStr(dobMax)}
required
/>
<FormRow
Expand All @@ -173,7 +196,8 @@ export default function SignupPagePatient() {
<FormRow
label="NIC No"
value={nicNo}
onChange={(e) => setNicNo(e.target.value)}
onChange={(e) => setNicNo(e.target.value.replace(/\D/g, ""))}
inputMode="numeric"
required
/>

Expand Down Expand Up @@ -209,7 +233,8 @@ export default function SignupPagePatient() {
label="Contact No"
type="tel"
value={contactNo}
onChange={(e) => setContactNo(e.target.value)}
onChange={(e) => setContactNo(e.target.value.replace(/\D/g, ""))}
inputMode="numeric"
required
/>

Expand Down Expand Up @@ -246,7 +271,8 @@ export default function SignupPagePatient() {
label="Guardian's Contact No"
type="tel"
value={guardianContactNo}
onChange={(e) => setGuardianContactNo(e.target.value)}
onChange={(e) => setGuardianContactNo(e.target.value.replace(/\D/g, ""))}
inputMode="numeric"
required
/>
</div>
Expand Down
Loading