Skip to content
Closed
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
11 changes: 6 additions & 5 deletions frontend/src/pages/auth/Signup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ const Signup = ({ onAuthSuccess = () => {} }) => {
[form.username]
);
const nameValid = form.name.trim().length >= 2;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the changes, and for fixing the conflict errors!

const dateOfBirthValid = useMemo(
() => isValidDateOfBirth(form.dateOfBirth),
[form.dateOfBirth],
);

const dateOfBirthValid = isValidDateOfBirth(form.dateOfBirth);

const genderValid = ['male', 'female', 'other', 'na'].includes(form.gender);
const phoneValid = /^\+?[0-9]{10,15}$/.test(form.phone);
const passwordValid = useMemo(
Expand Down Expand Up @@ -231,7 +230,9 @@ const Signup = ({ onAuthSuccess = () => {} }) => {
<option value="na">{t('common:preferNotToSay', 'Prefer not to say')}</option>
</select>
{touched.gender && !genderValid && (
<p className="text-xs text-red-600 mt-1">{t('auth:errors.genderRequired', 'Please select a gender')}</p>
<p className="text-xs text-red-600 mt-1">
{t('auth:errors.genderRequired', 'Please select a gender')}
</p>
)}
</div>
</div>
Expand Down
22 changes: 12 additions & 10 deletions frontend/src/pages/auth/Signup.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ describe('Signup', () => {
});

it('requires a date of birth', async () => {
const user = userEvent.setup();
renderSignup();
const dobInput = screen.getByLabelText(/date of birth/i);

screen.getByLabelText(/date of birth/i).focus();
await user.tab();
fireEvent.focus(dobInput);
fireEvent.blur(dobInput);

expect(screen.getByText(/date of birth is required/i)).toBeInTheDocument();
});
Expand Down Expand Up @@ -211,14 +211,16 @@ describe('Signup', () => {
await user.type(screen.getByLabelText(/full name/i), 'John Doe');
fireEvent.change(screen.getByLabelText(/date of birth/i), { target: { value: '2000-01-01' } });
await user.selectOptions(screen.getByRole('combobox'), 'male');

// Try to type letters - they should be stripped

const phoneInput = screen.getByPlaceholderText(/phone number/i);
await user.type(phoneInput, '123abc4567890');

await user.type(screen.getByLabelText(/^password$/i), 'Password123');
await user.type(screen.getByLabelText(/confirm password/i), 'Password123');
await user.click(screen.getByRole('button', { name: /sign up/i }));
await user.type(phoneInput, '123-456-7890');

await user.type(screen.getByLabelText(/^password$/i), 'Password123!');
await user.type(screen.getByLabelText(/confirm password/i), 'Password123!');

const submitButton = screen.getByRole('button', { name: /sign up/i });
expect(submitButton).toBeEnabled();
await user.click(submitButton);

await waitFor(() => {
expect(mockSignup).toHaveBeenCalledWith(
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/utils/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,19 @@ export const validatePassword = (value) => {
return checks.hasUppercase && checks.hasNumber;
};

export const isValidDateOfBirth = (value) => {
if (!value) return false;
const dob = new Date(value);
if (Number.isNaN(dob.getTime())) return false;
const today = new Date();
let age = today.getFullYear() - dob.getFullYear();
const m = today.getMonth() - dob.getMonth();
if (m < 0 || (m === 0 && today.getDate() < dob.getDate())) {
age--;
}
return age >= 13 && age <= 120;
};

export const formatDateForInput = (date = new Date()) => {
return date.toISOString().split('T')[0];
};
16 changes: 8 additions & 8 deletions frontend/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ export default {
extend: {
colors: {
health: {
primary: '#0f766e', // (Teal)
secondary: '#059669', // (Emerald)
good: '#10b981', // Normal (Green)
warning: '#f59e0b', // Caution (Orange)
critical: '#ef4444', // Danger (Red)
surface: '#f0fdfa', // Background (Teal-50)
primary: '#0f766e',
secondary: '#059669',
good: '#10b981',
warning: '#f59e0b',
critical: '#ef4444',
surface: '#f0fdfa',
}
}
},
},
},
plugins: [],
}
}
Loading