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
673 changes: 370 additions & 303 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"@tinymce/tinymce-react": "^5.1.1",
"@vercel/analytics": "^1.3.1",
"@vercel/speed-insights": "^1.0.12",
"antd": "^5.18.1",
"axios": "^1.7.2",
"antd": "^5.22.2",
"axios": "^1.7.8",
"clsx": "^2.1.1",
"dayjs": "^1.11.11",
"emailjs-com": "^3.2.0",
Expand Down Expand Up @@ -105,9 +105,9 @@
"eslint-plugin-unused-imports": "^3.2.0",
"postcss": "^8.4.38",
"prettier": "^3.3.2",
"tailwindcss": "^3.4.4",
"tailwindcss": "^3.4.11",
"typescript": "^4.9.5",
"vite": "^5.3.0",
"vite": "^5.4.11",
"vitest": "^1.6.0"
},
"volta": {
Expand Down
37 changes: 37 additions & 0 deletions src/components/Admin/DashboardStore/DashboardStore.hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Form, FormInstance, FormProps } from 'antd';
import { useCallback, useEffect, useState } from 'react';
import { IStore, StoreService } from '../../../services/admin/store';

interface IDashboardStoreHooks {
form: FormInstance<IStore>
items: IStore[]
onAddArticle: (values: IStore) => void
deleteArticle: (articleId: string) => void
}

export const useDashboardStore = (): IDashboardStoreHooks => {
const [form] = Form.useForm();
const [items, setItems] = useState<IStore[]>([]);

const onAddArticle: FormProps<IStore>['onFinish'] = useCallback(({ name, price }): void => {
StoreService.addArticle({ name, price, }).then((res) => setItems((prevState) => [...prevState, res]));
form.resetFields();
}, []);

const deleteArticle = useCallback((articleId: string): void => {
StoreService.removeArticle(articleId).then(() =>
setItems((prevState) => prevState.filter((item) => item.id !== articleId))
);
}, []);

useEffect(() => {
StoreService.getAllArticles().then(setItems);
}, []);

return {
form,
items,
onAddArticle,
deleteArticle,
};
};

Check warning on line 37 in src/components/Admin/DashboardStore/DashboardStore.hooks.ts

View check run for this annotation

Codecov / codecov/patch

src/components/Admin/DashboardStore/DashboardStore.hooks.ts#L2-L37

Added lines #L2 - L37 were not covered by tests
53 changes: 53 additions & 0 deletions src/components/Admin/DashboardStore/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import Navigation from '../../../pages/admin/Navigation';
import { Button, Divider, Flex, Form, Input, InputNumber, Typography } from 'antd';
import { formattedPrice } from '../../../lib/form';
import { CloseCircleOutlined } from '@ant-design/icons';
import { useDashboardStore } from './DashboardStore.hooks';

const DashboardStore: React.FC = () => {
const { form, items, onAddArticle, deleteArticle } = useDashboardStore();
return (
<Navigation>
<p className="text-xl mb-2">Liste des articles : </p>
<Form layout="inline" name="addArticle" form={form} onFinish={onAddArticle}>
<Form.Item name="name" rules={[{ required: true, message: 'Veuillez rentrer un nom d\'article' }]}>
<Input placeholder="Nom de l'article"/>
</Form.Item>
<Form.Item name="price" rules={[{ required: true, message: 'Veuillez rentrer un prix' }]}>
<InputNumber min={0} step={0.5} placeholder="Prix"/>
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit" className="button">Ajouter</Button>
</Form.Item>
</Form>
<Divider/>
<Flex gap={8} className="mt-4">
{items.length > 0 ? items.map((article) => (
<div key={article.id} className="flex bg-white rounded-md p-2 aspect-[1/1] w-28">
<Flex vertical justify="space-between" gap={8} className="w-full">
<Flex align="center" justify="space-between" className="w-full">
<Typography.Text strong>
{article.name}
</Typography.Text>
<Button
shape="circle"
variant="filled"
color="danger"
size="small"
icon={<CloseCircleOutlined/>}
onClick={() => deleteArticle(article.id)}
/>
</Flex>
<Typography.Text>
{formattedPrice(article.price)}
</Typography.Text>
</Flex>
</div>
)) : <div>Aucun article créé</div>}
</Flex>
</Navigation>
);
};

export default DashboardStore;

Check warning on line 53 in src/components/Admin/DashboardStore/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/Admin/DashboardStore/index.tsx#L2-L53

Added lines #L2 - L53 were not covered by tests
2 changes: 2 additions & 0 deletions src/components/Routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
const DashboardTrombinoscope = loadable(() => import('../Admin/DashboardTrombinoscope'));
const DashboardVote = loadable(() => import('../Admin/DashboardVote'));
const DashboardVoteStatistics = loadable(() => import('../Admin/DashboardVoteStatistics'));
const DashboardStore = loadable(() => import('../Admin/DashboardStore'));

Check warning on line 23 in src/components/Routes/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/Routes/index.tsx#L23

Added line #L23 was not covered by tests
const Footer = loadable(() => import('../../components/Footer'));
import Navbar from '../../components/Navbar';

Expand All @@ -35,6 +36,7 @@
<Route path={RouterUrl.adminTrombinoscope} element={<DashboardTrombinoscope />} />
<Route path={RouterUrl.adminVote} element={<DashboardVote />} />
<Route path={RouterUrl.adminVoteStatistics} element={<DashboardVoteStatistics />} />
<Route path={RouterUrl.adminStore} element={<DashboardStore />} />

Check warning on line 39 in src/components/Routes/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/Routes/index.tsx#L39

Added line #L39 was not covered by tests

<Route path={RouterUrl.home} element={<Dashboard />} />
</RouterRoutes>
Expand Down
1 change: 1 addition & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
adminTrombinoscope = '/trombinoscope',
adminVote = '/votes',
adminVoteStatistics = '/votes/:voteId',
adminStore = '/store',

Check warning on line 24 in src/constants/index.ts

View check run for this annotation

Codecov / codecov/patch

src/constants/index.ts#L24

Added line #L24 was not covered by tests

notFound = '*',
}
Expand Down
5 changes: 5 additions & 0 deletions src/lib/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
}
});
};

export const formattedPrice = (price: number): string => new Intl.NumberFormat('fr-FR', {
style: 'currency',
currency: 'EUR'
}).format(price).padEnd(4, '0');

Check warning on line 12 in src/lib/form.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/form.ts#L8-L12

Added lines #L8 - L12 were not covered by tests
6 changes: 6 additions & 0 deletions src/pages/admin/Navigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
MenuOutlined,
PlayCircleOutlined,
QuestionCircleOutlined,
ShopOutlined,

Check warning on line 9 in src/pages/admin/Navigation/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/admin/Navigation/index.tsx#L9

Added line #L9 was not covered by tests
TeamOutlined,
VideoCameraOutlined,
} from '@ant-design/icons';
Expand Down Expand Up @@ -53,6 +54,11 @@
link: RouterUrl.adminVote,
icon: <QuestionCircleOutlined />,
},
{
name: 'Magasin',
link: RouterUrl.adminStore,
icon: <ShopOutlined />,
},

Check warning on line 61 in src/pages/admin/Navigation/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/admin/Navigation/index.tsx#L57-L61

Added lines #L57 - L61 were not covered by tests
];

interface NavigationProps {
Expand Down
2 changes: 2 additions & 0 deletions src/services/admin/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './store.interface';
export * from './store.service';

Check warning on line 2 in src/services/admin/store/index.ts

View check run for this annotation

Codecov / codecov/patch

src/services/admin/store/index.ts#L2

Added line #L2 was not covered by tests
6 changes: 6 additions & 0 deletions src/services/admin/store/store.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface IStore {
id: string
name: string
price: number
image?: string
}
8 changes: 8 additions & 0 deletions src/services/admin/store/store.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { IStore } from './store.interface';
import axiosInstance from '../../axios';

export class StoreService {
static getAllArticles = async (): Promise<IStore[]> => (await axiosInstance.get('/store')).data;
static addArticle = async ({ name, price }: Partial<IStore>): Promise<IStore> => (await axiosInstance.post('/store', { name, price })).data;
static removeArticle = async (id: string): Promise<void> => (await axiosInstance.delete(`/store/${id}`)).data;
}

Check warning on line 8 in src/services/admin/store/store.service.ts

View check run for this annotation

Codecov / codecov/patch

src/services/admin/store/store.service.ts#L2-L8

Added lines #L2 - L8 were not covered by tests