Skip to content

Commit

Permalink
DISPLAY-993: Fixed user activation flow
Browse files Browse the repository at this point in the history
  • Loading branch information
tuj committed Sep 22, 2023
1 parent 4bda92a commit 8ca0f69
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
29 changes: 13 additions & 16 deletions src/components/activation-code/activation-code-activate.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import { React, useState, useEffect } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import {
usePostV1ExternalUserActivationCodesActivateMutation,
usePostV1ExternalUserActivationCodesMutation
} from "../../redux/api/api.generated";
import ActivationCodeForm from "./activation-code-form";
import Form from "react-bootstrap/Form";
import { Button } from "react-bootstrap";
import { usePostV1ExternalUserActivationCodesActivateMutation } from "../../redux/api/api.generated";
import {
displaySuccess,
displayError
displayError,
} from "../util/list/toast-component/display-toast";
import LoadingComponent from "../util/loading-component/loading-component";
import Form from "react-bootstrap/Form";
import ContentBody from "../util/content-body/content-body";
import FormInput from "../util/forms/form-input";
import RadioButtons from "../util/forms/radio-buttons";
import ContentFooter from "../util/content-footer/content-footer";
import { Button } from "react-bootstrap";

/**
* The user create component.
Expand All @@ -25,17 +20,16 @@ import { Button } from "react-bootstrap";
*/
function ActivationCodeActivate() {
const { t } = useTranslation("common", {
keyPrefix: "activation-code-create"
keyPrefix: "activation-code-create",
});
const navigate = useNavigate();
const headerText = t("activate-activation-code-header");
const [formStateObject, setFormStateObject] = useState({
activationCode: ""
activationCode: "",
});

const [
PostV1ExternalUserActivationCodeActivate,
{ error: saveError, isLoading: isSaving, isSuccess: isSaveSuccess }
{ error: saveError, isLoading: isSaving, isSuccess: isSaveSuccess },
] = usePostV1ExternalUserActivationCodesActivateMutation();

/** Handle submitting is done. */
Expand Down Expand Up @@ -69,15 +63,18 @@ function ActivationCodeActivate() {
const handleSubmit = () => {
PostV1ExternalUserActivationCodeActivate({
externalUserActivationCodeExternalUserActivateInput:
JSON.stringify(formStateObject)
JSON.stringify(formStateObject),
});
};

return (
<>
<LoadingComponent isLoading={isSaving} loadingMessage={t("loading-messages.saving-activation-code")} />
<LoadingComponent
isLoading={isSaving}
loadingMessage={t("loading-messages.saving-activation-code")}
/>
<Form>
<h1 id="h1ActivationCode">{t('header')}</h1>
<h1 id="h1ActivationCode">{t("header")}</h1>
<ContentBody>
<FormInput
title="activation-code"
Expand Down
19 changes: 12 additions & 7 deletions src/components/user/login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ function Login() {

// Set data in local storage, to persist login on refresh
localStorage.setItem(localStorageKeys.API_TOKEN, data.token);
localStorage.setItem(localStorageKeys.API_REFRESH_TOKEN, data.refresh_token);
localStorage.setItem(
localStorageKeys.API_REFRESH_TOKEN,
data.refresh_token
);
localStorage.setItem(localStorageKeys.USER_NAME, user?.fullname);
localStorage.setItem(localStorageKeys.EMAIL, user?.email);
localStorage.setItem(localStorageKeys.TENANTS, JSON.stringify(tenants));
Expand Down Expand Up @@ -114,14 +117,16 @@ function Login() {
ConfigLoader.loadConfig().then((config) => {
fetch(`${config.api}v1/authentication/token/refresh`, {
mode: "cors",
method: 'POST',
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
credentials: "include",
body: JSON.stringify({
refresh_token: localStorage.getItem(localStorageKeys.API_REFRESH_TOKEN),
})
refresh_token: localStorage.getItem(
localStorageKeys.API_REFRESH_TOKEN
),
}),
})
.then((resp) => resp.json())
.then((data) => {
Expand All @@ -138,7 +143,7 @@ function Login() {
displayError(t("error-refreshing-code"), err);
});
});
}
};

const onActivationCodeSubmit = (e) => {
e.preventDefault();
Expand All @@ -151,7 +156,7 @@ function Login() {
}),
})
)
.then((resp) => {
.then(() => {
refreshTokenAndLogin();
})
.catch((err) => {
Expand Down
2 changes: 1 addition & 1 deletion src/redux/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ generatedApi.enhanceEndpoints({
"FeedSource",
"Feed",
"ActivationCode",
"User"
"User",
],
endpoints: {
getV1FeedSources: {
Expand Down

0 comments on commit 8ca0f69

Please sign in to comment.