Skip to content

Commit

Permalink
display the email, firstName, lastName or last_name of the user in th…
Browse files Browse the repository at this point in the history
…e last step, StepFive component
  • Loading branch information
marvinsjsu committed Sep 6, 2023
1 parent 458a633 commit df04b15
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
18 changes: 11 additions & 7 deletions client/src/components/Users/Auth/SignUpCitizen/SignUpCitizen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useState, useEffect } from 'react';
import { Box, Typography } from '@mui/material';
import { useMutation } from 'react-query';

Expand All @@ -14,8 +14,8 @@ import StepTwo from './StepTwo';
import StepThree from './StepThree';
import StepFour from './StepFour';
import StepFive from './StepFive';

import Endpoints from './apis/backend';

import { AxiosError } from 'axios';

const imgHeight = '569px';
Expand All @@ -39,15 +39,19 @@ const initialFormData: UserSignupData = {
function SignupCitizen() {
const [activeStep, setActiveStep] = useState<number>(0);
const [formData, setFormData] = useState(initialFormData);
const [user, setUser] = useState<UserSignupData | null>(null);
const [errorMsg, setErrorMsg] = useState<string | null>(null);
const [user, setUser] = useState(null);
const [errorMsg, setErrorMsg] = useState(null);

useEffect(() => {
if (user) {
setActiveStep((prevActiveStep) => prevActiveStep + 1);
}
}, [user]);

const registerUserMutation = useMutation({
mutationFn: Endpoints.userRegister,
onSuccess: (user) => {
// @ts-ignore
onSuccess: ({ data: user }) => {
setUser(user);
setActiveStep((prevActiveStep) => prevActiveStep + 1);
},
onError: (error: AxiosError) => {
console.log('WE HAVE AN ERROR', { error });
Expand Down
9 changes: 6 additions & 3 deletions client/src/components/Users/Auth/SignUpCitizen/StepFive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ import { Box, Typography } from '@mui/material';

import { useStyles } from './styles/styles';

interface StepFiveType {
export interface IStepFive {
user?: {
firstName?: string;
lastName?: string;
last_name?: string;
email?: string;
} | null;
}

export default function StepFive({ user }: StepFiveType) {
export default function StepFive({ user }: IStepFive) {
const { classes } = useStyles();

console.log('StepFive: ', { user });

return (
<Box sx={{ height: '100%', minWidth: '780px' }}>
<Typography
Expand All @@ -26,7 +29,7 @@ export default function StepFive({ user }: StepFiveType) {
Sign up almost complete!
</Typography>
<Typography className={classes.label} sx={{ fontWeight: 'bold', marginTop: '60px' }}>
{user && user.firstName} {user && user.lastName}
{user && user.firstName} {user && (user.lastName || user.last_name)}
</Typography>
<Typography>{user && user.email}</Typography>
<Typography sx={{ marginBottom: '60px' }}>
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/Users/Auth/SignUpCitizen/StepTwo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const initialFormData = {
error: null,
rule: string()
.required('Required.')
.min(5, 'Zipcode is too short - should be 5 digits minimum.'),
.min(5, 'Zipcode should be 5 digits minimum.')
.matches(/^\d{5}(?:[-\s]\d{4})?$/, 'Must be a valid zip code.'),
},
};

Expand Down

0 comments on commit df04b15

Please sign in to comment.