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

Add validation for activation code and error logging for createFamily in Parent Signup flow #1014

Merged
merged 12 commits into from
Feb 3, 2025
Merged
37 changes: 31 additions & 6 deletions src/components/auth/RegisterChildren.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
:feedback="false"
></PvPassword>
</div>
<span v-if="v$.students.$each.$response.$data[outerIndex].password.$invalid && submitted">
<span v-if="v$.students.$each.$response.$errors[outerIndex].password.length > 0 && submitted">
<span
v-for="(error, innerIndex2) in v$.students.$each.$response.$errors[outerIndex].password"
:key="`error-${outerIndex}-${innerIndex2}`"
Expand All @@ -127,7 +127,7 @@
:feedback="false"
></PvPassword>
</div>
<span v-if="isPasswordMismatch(outerIndex) && submitted" class="p-error"> Passwords must match </span>
<span v-if="isPasswordMismatch(outerIndex)" class="p-error"> Passwords must match </span>
</div>
</section>
<section class="form-section">
Expand Down Expand Up @@ -348,7 +348,7 @@
type="submit"
label="Submit"
class="bg-primary text-white border-none border-round w-4 p-2 h-3rem mr-3 hover:surface-300 hover:text-black-alpha-90"
@click.prevent="handleFormSubmit(!v$.$invalid)"
@click.prevent="handleFormSubmit(!v$.$invalid && !anyPasswordsMismatched())"
/>
<PvDialog
v-model:visible="isDialogVisible"
Expand Down Expand Up @@ -564,15 +564,18 @@ function isPasswordMismatch(index) {
return state.students[index].password !== state.students[index]?.confirmPassword;
}

function anyPasswordsMismatched() {
return state.students.some((student) => student.password !== student.confirmPassword);
}

const v$ = useVuelidate(rules, state);

const handleFormSubmit = async (isFormValid) => {
submitted.value = true;

if (!isFormValid) {
dialogMessage.value = 'Please fill out all the required fields.';
dialogMessage.value = 'There is an error with the form input, please correct and re-try.';
showErrorDialog();
submitted.value = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just want to double check that this line was intentionally removed, and not by mistake.

Is this because we want to trigger the conditional rendering of the error messages based on submitted being true after we attempt to submit the form?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is correct, previously the submitted.value = false would prevent the error message from rendering.

return;
}

Expand Down Expand Up @@ -614,7 +617,29 @@ const validateCode = async (studentCode, outerIndex = 0) => {

try {
const activationCode = await fetchDocById('activationCodes', studentCode, undefined, 'admin', true, true);

// If two months have elapsed since creation, we should invalidate the code as expired
if (activationCode.dateExpired) {
const dateExpired = new Date(activationCode.dateExpired);
const today = new Date();
if (dateExpired < today) {
dialogMessage.value = 'The code has expired. Please enter a valid code."';
showErrorDialog();
submitted.value = false;
return;
}
}
// if no dateExpired, fallback to dateCreated to check for validity
else if (activationCode.dateCreated) {
const dateCreated = new Date(activationCode.dateCreated);
const twoMonthsAgo = new Date();
twoMonthsAgo.setMonth(twoMonthsAgo.getMonth() - 2);
if (dateCreated < twoMonthsAgo) {
dialogMessage.value = 'The code has expired. Please enter a valid code."';
showErrorDialog();
submitted.value = false;
return;
}
}
if (activationCode.orgId) {
state.students[outerIndex].orgName = `${_capitalize(activationCode.orgType)} - ${
activationCode.orgName ?? activationCode.orgId
Expand Down
16 changes: 13 additions & 3 deletions src/pages/RegisterFamilyUsers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
<div class="text-sm font-bold text-red-800 ml-1 uppercase">beta</div>
</div>
<div class="bg-gray-100 rounded p-2">
<div class="flex flex-wrap text-gray-600 text-md font-bold">Register a parent or guardian account.</div>
<div class="flex flex-wrap text-gray-600 text-md font-bold">
Register a parent or guardian account for ROAR Research Portal
</div>
<div class="flex flex-wrap text-gray-400 text-sm">
This account will be used to manage your family's accounts.
This account allows your family to participate in ROAR research studies!
</div>
<div class="flex flex-wrap text-gray-400 text-sm">
You will be able to add children to your family in the next step.
Expand All @@ -27,7 +29,9 @@
<div class="text-sm font-bold text-red-800 ml-1 uppercase">beta</div>
</div>
<div class="bg-gray-100 rounded p-2">
<div class="flex flex-wrap text-gray-600 text-md font-bold">Register children or students.</div>
<div class="flex flex-wrap text-gray-600 text-md font-bold">
Register children or students for ROAR Research Portal
</div>
<div class="flex flex-wrap text-gray-400 text-sm">
These accounts will be linked to your parent/guardian account.
</div>
Expand Down Expand Up @@ -217,6 +221,12 @@ watch([parentInfo, studentInfo], ([newParentInfo, newStudentInfo]) => {
dialogHeader.value = 'Success!';
dialogMessage.value = 'Your family has been created!';
showDialog();
})
.catch((error) => {
spinner.value = false;
dialogHeader.value = 'Error!';
dialogMessage.value = error.message;
showDialog();
});
}
});
Expand Down