Skip to content
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
51 changes: 26 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/pages/SignUp/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ describe('SignUp', () => {
email: 'test@example.com',
password: 'password123',
first_name: 'John',
last_name: ''
last_name: '',
invitation_token: ''
});
});

Expand Down Expand Up @@ -135,7 +136,8 @@ describe('SignUp', () => {
email: 'test@example.com',
password: 'password123',
first_name: 'John',
last_name: 'Doe'
last_name: 'Doe',
invitation_token: ''
});
});

Expand Down
22 changes: 18 additions & 4 deletions src/pages/SignUp/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import * as Yup from 'yup';
import './index.scss';
import { useFormik } from "formik";
import AuthRequests, { SignUpData } from "../../services/requests/AuthRequests";
import { useHistory } from "react-router-dom";
import { useHistory, useLocation } from "react-router-dom";
import { Button, Form, FormControl, FormLabel } from "react-bootstrap";
import Page from "../../components/Template/Page";

const SignUp: React.FC = () => {
const history = useHistory();
const location = useLocation();
const [error, setError] = useState<string | null>(null);

const searchParams = new URLSearchParams(location.search);
const invitationToken = searchParams.get('invite') || '';

const SignupSchema = Yup.object().shape({
email: Yup.string()
.email('Invalid email format')
Expand All @@ -37,8 +41,17 @@ const SignUp: React.FC = () => {
setError('Unknown Error');
}
} catch (error: unknown) {
if (typeof error === 'object' && error !== null && 'status' in error && (error as { status: unknown }).status === 409) {
setError('Email already exists.');
if (typeof error === 'object' && error !== null && 'status' in error) {
const status = (error as { status: number }).status;
if (status === 409) {
setError('Email already exists.');
} else if (status === 400) {
setError('Invalid invitation token.');
} else if (status === 404) {
setError('Invitation token not found or has expired.');
} else {
setError('Failed to create account. Please try again.');
}
} else {
setError('Failed to create account. Please try again.');
}
Expand All @@ -50,7 +63,8 @@ const SignUp: React.FC = () => {
email: '',
password: '',
first_name: '',
last_name: ''
last_name: '',
invitation_token: invitationToken
},
validationSchema: SignupSchema,
onSubmit: submit
Expand Down
1 change: 1 addition & 0 deletions src/services/requests/AuthRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface SignUpData {
password: string;
first_name: string;
last_name: string;
invitation_token?: string;
}

export default class AuthRequests {
Expand Down
Loading