mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-22 20:01:59 +00:00
Implement create account function
This commit is contained in:
@@ -19,6 +19,7 @@ import Account from '@src/pages/Account';
|
|||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
import * as PATH from './constants/path';
|
import * as PATH from './constants/path';
|
||||||
|
import SignUpAccount from "@src/pages/SignUpAccount";
|
||||||
|
|
||||||
const queryClient = new QueryClient();
|
const queryClient = new QueryClient();
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ function App() {
|
|||||||
<Route path={PATH.USER} element={<User />} />
|
<Route path={PATH.USER} element={<User />} />
|
||||||
<Route path={PATH.ROOM} element={<Room />} />
|
<Route path={PATH.ROOM} element={<Room />} />
|
||||||
<Route path={PATH.ACCOUNT} element={<Account />} />
|
<Route path={PATH.ACCOUNT} element={<Account />} />
|
||||||
|
<Route path={PATH.SIGN_UP_ACCOUNT} element={<SignUpAccount />} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path={PATH.LOGIN} element={<Login />} />
|
<Route path={PATH.LOGIN} element={<Login />} />
|
||||||
<Route path={PATH.OTHER_PATH} element={<NotFound />} />
|
<Route path={PATH.OTHER_PATH} element={<NotFound />} />
|
||||||
|
|||||||
@@ -2,17 +2,21 @@
|
|||||||
import HeaderMenu from '../HeaderMenu';
|
import HeaderMenu from '../HeaderMenu';
|
||||||
|
|
||||||
// Styled
|
// Styled
|
||||||
import { StyledHeader } from './styled';
|
import {StyledHeader} from './styled';
|
||||||
|
|
||||||
interface IHeader {
|
interface IHeader {
|
||||||
accountName: string;
|
accountName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Header = ({ accountName }: IHeader) => {
|
const Header = ({accountName}: IHeader) => {
|
||||||
return (
|
return (
|
||||||
<StyledHeader>
|
<StyledHeader>
|
||||||
<p>Hi, {accountName}!</p>
|
<p>Hi, {
|
||||||
<HeaderMenu />
|
accountName
|
||||||
|
? accountName
|
||||||
|
: 'Admin'
|
||||||
|
}!</p>
|
||||||
|
<HeaderMenu/>
|
||||||
</StyledHeader>
|
</StyledHeader>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ import { BsHouseDoorFill } from 'react-icons/bs';
|
|||||||
import { StyledNav, StyledNavLink } from './styled';
|
import { StyledNav, StyledNavLink } from './styled';
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
import { BOOKING, ROOM, USER } from '@src/constants/path';
|
import {BOOKING, ROOM, SIGN_UP_ACCOUNT, USER} from '@src/constants/path';
|
||||||
|
import {FaUserPlus} from "react-icons/fa6";
|
||||||
|
|
||||||
const Nav = () => {
|
const Nav = () => {
|
||||||
return (
|
return (
|
||||||
@@ -24,6 +25,10 @@ const Nav = () => {
|
|||||||
<BsHouseDoorFill />
|
<BsHouseDoorFill />
|
||||||
<span>Room</span>
|
<span>Room</span>
|
||||||
</StyledNavLink>
|
</StyledNavLink>
|
||||||
|
<StyledNavLink to={SIGN_UP_ACCOUNT}>
|
||||||
|
<FaUserPlus />
|
||||||
|
<span>Create Account</span>
|
||||||
|
</StyledNavLink>
|
||||||
</StyledNav>
|
</StyledNav>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
const INVALID_FIELD = 'This field is invalid format!';
|
const INVALID_FIELD = 'This field is invalid format!';
|
||||||
const INVALID_PHONE = 'Phone number is invalid!';
|
const INVALID_PHONE = 'Phone number is invalid!';
|
||||||
const REQUIRED_FIELD_ERROR = 'This field is required!';
|
const REQUIRED_FIELD_ERROR = 'This field is required!';
|
||||||
const INVALID_DISCOUNT = 'Discount should be greater than 0 and less than 100!';
|
|
||||||
const PASSWORD_CONDITION =
|
const PASSWORD_CONDITION =
|
||||||
'Your password must have 1 uppercase, 1 lowercase, 1 special character, min 1 number and the length between from 8 to 16!';
|
'Your password must have 1 uppercase, 1 lowercase, 1 special character, min 1 number and the length between from 8 to 16!';
|
||||||
const INVALID_PASSWORD = 'Invalid password';
|
const INVALID_PASSWORD = 'Invalid password';
|
||||||
const PASSWORD_NOT_MATCH = 'Password not match!';
|
const PASSWORD_NOT_MATCH = 'Password not match!';
|
||||||
const PASSWORD_NOT_MATCH_REQUIREMENT = 'Password not match the requirement!';
|
const PASSWORD_NOT_MATCH_REQUIREMENT = 'Password not match the requirement!';
|
||||||
const INVALID_EMAIL = 'Invalid email address';
|
const INVALID_EMAIL = 'Invalid email address';
|
||||||
|
const INVALID_STRING = 'This field need more than 5 characters!';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
REQUIRED_FIELD_ERROR,
|
REQUIRED_FIELD_ERROR,
|
||||||
INVALID_DISCOUNT,
|
|
||||||
INVALID_FIELD,
|
INVALID_FIELD,
|
||||||
INVALID_PHONE,
|
INVALID_PHONE,
|
||||||
PASSWORD_CONDITION,
|
PASSWORD_CONDITION,
|
||||||
@@ -19,4 +18,5 @@ export {
|
|||||||
PASSWORD_NOT_MATCH,
|
PASSWORD_NOT_MATCH,
|
||||||
PASSWORD_NOT_MATCH_REQUIREMENT,
|
PASSWORD_NOT_MATCH_REQUIREMENT,
|
||||||
INVALID_EMAIL,
|
INVALID_EMAIL,
|
||||||
|
INVALID_STRING
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const BOOKING = '/booking';
|
|||||||
const USER = '/user';
|
const USER = '/user';
|
||||||
const ROOM = '/room';
|
const ROOM = '/room';
|
||||||
const ACCOUNT = '/account';
|
const ACCOUNT = '/account';
|
||||||
|
const SIGN_UP_ACCOUNT = '/createAccount'
|
||||||
const OTHER_PATH = '*';
|
const OTHER_PATH = '*';
|
||||||
const LOGIN = 'login';
|
const LOGIN = 'login';
|
||||||
|
|
||||||
@@ -12,4 +13,5 @@ export {
|
|||||||
ACCOUNT,
|
ACCOUNT,
|
||||||
OTHER_PATH,
|
OTHER_PATH,
|
||||||
LOGIN,
|
LOGIN,
|
||||||
|
SIGN_UP_ACCOUNT,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ const StyledLoginForm = styled.div`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const FieldInput = styled.input`
|
const FieldInput = styled.input`
|
||||||
${CommonInput}
|
${CommonInput};
|
||||||
|
|
||||||
width: 300px;
|
width: 300px;
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import supabase from './supabaseService';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { IAccount } from '@src/types/account';
|
import { IAccount } from '@src/types/account';
|
||||||
|
import toast from 'react-hot-toast';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Login services
|
* Login services
|
||||||
@@ -82,4 +83,30 @@ const updateAccount = async ({ fullName, password }: IAccount) => {
|
|||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export { login, logout, getCurrentAccount, updateAccount };
|
const createAccount = async ({ email, password }: IAccount) => {
|
||||||
|
if (!email || !password) {
|
||||||
|
toast.error('Email and password is not valid!');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data, error } = await supabase.auth.signUp({
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
console.error(error.message);
|
||||||
|
throw new Error(error.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export {
|
||||||
|
login,
|
||||||
|
logout,
|
||||||
|
getCurrentAccount,
|
||||||
|
updateAccount,
|
||||||
|
createAccount
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
interface IAccount {
|
interface IAccount {
|
||||||
|
email?: string;
|
||||||
fullName?: string;
|
fullName?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user