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 loading spinner to submit button on self reg #791

Merged
merged 2 commits into from
Sep 4, 2023
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
15 changes: 10 additions & 5 deletions packages/client/src/pages/self_register/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const SelfRegisterPage: React.FC = () => {
// to more correctly control the 'isSubmitting' state
const submitForm: Parameters<
typeof CustomerForm.SelfReg
>[0]["onSave"] = async (values, { setErrors }) => {
>[0]["onSave"] = async (values, { setErrors, setSubmitting }) => {
const { secretKey, codeOk } = await customerSelfRegister(values)(
dispatch,
getState,
Expand All @@ -64,10 +64,15 @@ const SelfRegisterPage: React.FC = () => {
getFunctions: () => functions,
}
);
if (!codeOk) {
setErrors({
registrationCode: t(ValidationMessage.InvalidRegistrationCode),
});
try {
if (!codeOk) {
setErrors({
registrationCode: t(ValidationMessage.InvalidRegistrationCode),
});
setSubmitting(false);
}
} finally {
setSubmitting(false);
}
fadwamahmoud marked this conversation as resolved.
Show resolved Hide resolved

if (secretKey) {
Expand Down
35 changes: 35 additions & 0 deletions packages/e2e/integration/athlete_self_register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,39 @@ describe("Athlete self registration", () => {
t(Alerts.ContactEmail, { email: __emailFrom__ }).replace(/<\/?a.*>/g, "")
);
});

it("shows a spinner while the submit request is being processed", () => {
cy.getAttrWith("aria-label", t(AuthTitle.SignInWithEmail)).click();

const randomString = uuid().slice(0, 10);
const newEmail = `${randomString}@email.com`;

cy.getAttrWith("type", "email").type(newEmail);
cy.clickButton(t(ActionButton.Next));
cy.contains(t(AuthTitle.CreateAccount));

cy.getAttrWith("type", "password").type("non-relevant-password");
cy.clickButton(t(ActionButton.Save));

cy.intercept(
{
method: "POST",
url: "**/customerSelfRegister",
},
(req) => {
req.on("response", (res) => {
console.log("waiting");
res.setDelay(3000);
});
}
);

cy.getAttrWith("name", "name").type(saul.name);
cy.getAttrWith("name", "surname").type(saul.surname);
cy.getAttrWith("name", "birthday").type(saul.birthday);

cy.getAttrWith("name", "registrationCode").type(__registrationCode__);
cy.clickButton(t(ActionButton.Save));
cy.contains(t(ActionButton.Saving));
});
});
3 changes: 2 additions & 1 deletion packages/translations/src/dict/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@
"Verify": "Verify",
"Add": "Add",
"Edit": "Edit",
"Delete": "Delete"
"Delete": "Delete",
"Saving": "Saving"
},

"Notification": {
Expand Down
3 changes: 2 additions & 1 deletion packages/translations/src/dict/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@
"Verify": "Verifica",
"Edit": "Modifica",
"Add": "Aggiungi",
"Delete": "Elimina"
"Delete": "Elimina",
"Saving": "Salvataggio"
},

"Notification": {
Expand Down
1 change: 1 addition & 0 deletions packages/translations/src/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export enum ActionButton {
Add = "ActionButton.Add",
Edit = "ActionButton.Edit",
Delete = "ActionButton.Delete",
Saving = "ActionButton.Saving",
}
// #endregion dialog

Expand Down
10 changes: 8 additions & 2 deletions packages/ui/src/Forms/CustomerForm/FormSelfReg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ const FormSelfReg: React.FC<FormSelfRegProps> = ({
initialValues={initialValues}
onSubmit={(values, formikHelpers) => {
onSave(values, formikHelpers);
formikHelpers.setSubmitting(false);
}}
>
{({ isSubmitting, resetForm }) => (
Expand Down Expand Up @@ -92,7 +91,14 @@ const FormSelfReg: React.FC<FormSelfRegProps> = ({
color={FormButtonColor.Green}
disabled={isSubmitting}
>
{t(ActionButton.Save)}
{isSubmitting ? (
<>
<div className="w-4 h-4 border-t-2 border-blue-500 rounded-full animate-spin" />
{t(ActionButton.Saving)}
</>
) : (
t(ActionButton.Save)
)}
</FormButton>
</div>
</div>
Expand Down