Skip to content

Commit

Permalink
Merge pull request #59 from vgulerianb/vikrant/add-signup
Browse files Browse the repository at this point in the history
chore(SignUp): Integrate signup api
  • Loading branch information
vgulerianb committed Apr 14, 2023
2 parents f10f2ca + e78b773 commit 4f7fdb8
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 5 deletions.
6 changes: 6 additions & 0 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ import Sidebar from './components/Sidebar';
import Dashboard from './pages/Dashboard';
import FlowViewer from './pages/FlowViewer';
import Login from './pages/SignIn';
import SignUp from './pages/SignUp';

const AppRoutes = [
{
path: '/ui/login',
element: <Login />,
isPrivate: false
},
{
path: '/ui/signup',
element: <SignUp />,
isPrivate: false
},
{
path: '/ui/dashboard',
element: <Dashboard />,
Expand Down
8 changes: 8 additions & 0 deletions client/src/pages/SignIn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ const Login = () => {
Sign In
</Button>
</div>
<span
onClick={() => {
navigate('/ui/signup');
}}
className="cursor-pointer z-10 relative text-light-primary-blue-600 semiBold300 mt-[8px]"
>
Don't have an account? Sign Up
</span>

<div
style={{
Expand Down
70 changes: 65 additions & 5 deletions client/src/pages/SignUp/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
import { Button, CircularProgress } from '@mui/material';
import React, { useEffect, useRef, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useSignupMutation } from '../../redux/services/auth';

const SignUp = () => {
const navigate = useNavigate();
const [signup] = useSignupMutation();
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [email, setEmail] = useState('');

const isValidEmail = (email: string) => {
const re = /\S+@\S+\.\S+/;
return re.test(email);
};

const handleSignup = () => {
signup({
username,
password,
email
})
.unwrap()
.then((res) => {
console.log(res);
navigate('/ui/login');
})
.catch((err) => {
console.log(err);
});
};

return (
<div className={`flex relative flex-col prose-nbx items-center justify-center h-screen w-full`}>
Expand All @@ -17,11 +43,45 @@ const SignUp = () => {
Some text here to describe the app
</span>
</div>
<input className="w-full h-[40px]" placeholder="Full name" />
<input className="w-full h-[40px]" placeholder="Username" />
<input className="w-full h-[40px]" placeholder="Email" />
<input className="w-full h-[40px]" placeholder="Password" type={'password'} />
<Button className="h-[40px] mt-[8px!important] block" variant="contained" color="primary">
<input
value={username}
onChange={(e) => {
setUsername(e.target.value);
}}
className="w-full h-[40px]"
placeholder="Username"
/>
<input
onChange={(e) => {
setEmail(e.target.value);
}}
value={email}
className="w-full h-[40px]"
placeholder="Email"
/>
<input
onChange={(e) => {
setPassword(e.target.value);
}}
value={password}
className="w-full h-[40px]"
placeholder="Password"
type={'password'}
/>
<Button
disabled={
username.length === 0 ||
password.length === 0 ||
email.length === 0 ||
!isValidEmail(email)
}
onClick={() => {
handleSignup();
}}
className="h-[40px] mt-[8px!important] block"
variant="contained"
color="primary"
>
Create Account
</Button>
</div>
Expand Down
15 changes: 15 additions & 0 deletions client/src/redux/services/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ export const authApi = createApi({
body: credentials
})
}),
signup: builder.mutation<
DEFAULT_RESPONSE,
{
username: string;
email: string;
password: string;
}
>({
query: (credentials) => ({
url: '/signup',
method: 'POST',
body: credentials
})
}),
changePassword: builder.mutation<
DEFAULT_RESPONSE,
{
Expand Down Expand Up @@ -233,6 +247,7 @@ export const authApi = createApi({

export const {
useLoginMutation,
useSignupMutation,
useComponentsMutation,
useCreateBotMutation,
useGetBotsMutation,
Expand Down

0 comments on commit 4f7fdb8

Please sign in to comment.