Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(attendant): init #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3,128 changes: 884 additions & 2,244 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ export function AuthProvider({children}: IAuthProviderProps) {
}
}

async function signUp({ name, email, password }: SignUpProps) {
async function signUp({ name, email, password, role }: SignUpProps) {
try {
const { data } = await api.post('/user/', {
name,
email,
password,
role
});

toast.promise(
Expand Down
9 changes: 9 additions & 0 deletions src/interfaces/IItemsProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { OrderProps, ProductProps } from "@/types";

export interface IItemsProps {
id: string;
amount: number;
status: number;
order: OrderProps;
products: ProductProps;
}
2 changes: 2 additions & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ICategoryProps } from './ICategoryProps';
import { IHomeProps } from './IHomeProps';
import { IOrderItemProps } from './IOrderProps';
import { IModalORderProps } from './IModalOrderProps';
import { IItemsProps } from './IItemsProps';

export type {
IInputProps,
Expand All @@ -16,4 +17,5 @@ export type {
IHomeProps,
IOrderItemProps,
IModalORderProps,
IItemsProps,
}
22 changes: 13 additions & 9 deletions src/pages/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ export default function Dashboard({orders}: IHomeProps) {
case 0:
return 'ABERTO';
case 1:
return 'ATENDIDA';
return 'ATENDIDO';
case 2:
return 'FINALIZADO';
case 3:
return 'CANCELADO';
default:
return 'ABERTO';
Expand All @@ -38,6 +40,8 @@ export default function Dashboard({orders}: IHomeProps) {
case 1:
return styles.atendido;
case 2:
return styles.finalizado;
case 3:
return styles.cancelado;
default:
return styles.aberto;
Expand All @@ -46,39 +50,39 @@ export default function Dashboard({orders}: IHomeProps) {

async function handleOpenModalView(id: string) {
const apiClient = setupAPIClient();
const { data } = await apiClient.get(`order/${id}/item`)
const { data } = await apiClient.get(`orders/${id}/item`)

setModalItem(data);
setModalVIsible(true);
}

async function handleFinishItem(id: string) {
const apiClient = setupAPIClient();
await apiClient.patch(`/order/close/${id}`);
await apiClient.patch(`/orders/close/${id}`);

const { data } = await apiClient.get('/order/orders');
const { data } = await apiClient.get('/orders');
setOrderList(data);

setModalVIsible(false);
}

async function handleAttendItem(id: string) {
const apiClient = setupAPIClient();
await apiClient.patch(`/order/attend/${id}`);
await apiClient.patch(`/orders/attend/${id}`);

setModalVIsible(false);
}

async function handleCancelItem(id: string) {
const apiClient = setupAPIClient();
await apiClient.delete(`/order/${id}`);
await apiClient.delete(`/orders/${id}`);

setModalVIsible(false);
}

async function handleRefreshOrders() {
const apiClient = setupAPIClient();
const { data } = await apiClient.get('/order/orders');
const { data } = await apiClient.get('/orders/opened/');

setOrderList(data);
}
Expand All @@ -96,7 +100,7 @@ export default function Dashboard({orders}: IHomeProps) {

<main className={styles.container}>
<div className={styles.containerHeader}>
<h1>Últimos Pedidos</h1>
<h1>Últimos Pedidos</h1>
<button onClick={handleRefreshOrders}>
<FiRefreshCcw size={25} />
</button>
Expand Down Expand Up @@ -141,7 +145,7 @@ export default function Dashboard({orders}: IHomeProps) {

export const getServerSideProps = canSSRAuth(async (ctx) => {
const apiclient = setupAPIClient(ctx);
const { data } = await apiclient.get('/order/orders');
const { data } = await apiclient.get('/orders');

return {
props: {
Expand Down
5 changes: 5 additions & 0 deletions src/pages/dashboard/style.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
color: var(--green-900);
}

.finalizado {
color: var(--green-900);
text-decoration: line-through;
}

.cancelado {
color: var(--red-900);
}
Expand Down
101 changes: 101 additions & 0 deletions src/pages/item/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { Header } from '@/components/Header';
import { canSSRAuth } from '@/utils/casSSRAuth';
import Head from 'next/head';
import styles from './style.module.scss';
import { FormEvent, useState } from 'react';
import { setupAPIClient } from '@/services/api';
import { toast } from 'react-toastify';
import { IItemsProps } from '@/interfaces';

export default function ItemDashboard({amount, products, order}: IItemsProps) {
const [amountData, setAmountData] = useState(0);
const [productData, setProductData] = useState(products || []);
const [orderData, setOrder] = useState(order || []);

async function handleProducts() {
const apiClient = setupAPIClient();
const { data } = await apiClient.get('/products/');

setProductData(data);
}

async function hanldeOrders() {
const apiClient = setupAPIClient();
const { data } = await apiClient.get('/orders/')
}

async function handleRegister(evt: FormEvent) {
evt.preventDefault();

try {
const data = {
amountData,
productData,
orderData,
};

const apiClient = setupAPIClient();
await apiClient.post('/item/', data);
} catch (err) {
const errorMessage = err.reponse.data;
toast.error(
`Ops, algo de errado não está certo... ${errorMessage.error}: ${errorMessage.message}`,
{
position: toast.POSITION.TOP_CENTER,
theme: 'dark',
});
}
}

return (
<>
<Head>
<title>Novo Item - Tech Pizzaria</title>
</Head>
<div>
<Header />

<main className={styles.container}>
<h1>Novo item ao pedido</h1>

<form className={styles.form} onSubmit={handleRegister}>
<input
type="number"
placeholder='Quantidade'
className={styles.input}
value={amountData}
onChange={(evt) => setAmountData(Number(evt.target.value))}
/>

<input
type="text"
className={styles.input}
value={productData}
onChange={(evt) => setProductData(evt.target.value)}
/>

<input
type="text"
className={styles.input}
value={orderData}
onChange={(evt) => setOrderData(evt.target.value)}
/>
</form>
</main>
</div>
</>
)
}

export const getServerSideProps = canSSRAuth(async (ctx) => {
const apiClient = setupAPIClient(ctx);
const orders = await apiClient.get(`/orders`);
const products = await apiClient.get(`/products/`);

return {
props: {
orders: orders.data,
products: products.data,
},
};
});
4 changes: 4 additions & 0 deletions src/pages/item/style.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.container {

}

14 changes: 13 additions & 1 deletion src/pages/signup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function SignUp() {
const [name, setName] = useState<string>('');
const [email, setEmail] = useState<string>('');
const [password, setPassword] = useState<string>('');
const [isAdmin, setIsAdmin] = useState<boolean>(false);
const [loading, setLoading] = useState<boolean>(false);

async function handleSignUp(evt: FormEvent) {
Expand All @@ -36,6 +37,7 @@ export default function SignUp() {
name,
email,
password,
role: isAdmin ? 'administrador' : 'garcom',
}

await signUp(data);
Expand All @@ -52,7 +54,7 @@ export default function SignUp() {
<link rel="icon" href="/favicon.ico" />
</Head>
<main className={styles.containerCenter}>
<Image src={logo} alt="Logo Sujeito Pizzaria" />
<Image src={logo} alt="Logo Tech Pizzaria" />

<div className={styles.login}>
<h1>Criando sua conta</h1>
Expand All @@ -79,6 +81,16 @@ export default function SignUp() {
onChange={(ev: ChangeEvent<HTMLInputElement>) => setPassword(ev.target.value)}
/>

<div className={styles.checkbox}>
<label htmlFor="role">Selecione caso for usuario administrador:</label>
<input
className={styles.check}
type="checkbox"
checked={isAdmin}
onChange={(ev: ChangeEvent<HTMLInputElement>) => setIsAdmin(ev.target.checked)}
/>
</div>

<Button type="submit" loading={loading}>
Cadastrar
</Button>
Expand Down
16 changes: 16 additions & 0 deletions src/styles/Home.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@
cursor: pointer;
}

.checkbox {
display: flex;
align-items: center;
justify-content: center;
padding: 0 0 1.4rem 0;
color: var(--white-c);

label {
padding: 0 0.8rem;
}
}

.check {
cursor: pointer;
}

@media (max-width: 620px) {
.login {
width: 90%;
Expand Down
1 change: 1 addition & 0 deletions src/types/SignUpProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export type SignUpProps = {
name: string;
email: string;
password: string;
role: string;
}