|
| 1 | +import React from 'react'; |
| 2 | +import Navigation from '../../../pages/admin/Navigation'; |
| 3 | +import { Button, Divider, Flex, Form, Input, InputNumber, Typography } from 'antd'; |
| 4 | +import { formattedPrice } from '../../../lib/form'; |
| 5 | +import { CloseCircleOutlined } from '@ant-design/icons'; |
| 6 | +import { useDashboardStore } from './DashboardStore.hooks'; |
| 7 | + |
| 8 | +const DashboardStore: React.FC = () => { |
| 9 | + const { form, items, onAddArticle, deleteArticle } = useDashboardStore(); |
| 10 | + return ( |
| 11 | + <Navigation> |
| 12 | + <p className="text-xl mb-2">Liste des articles : </p> |
| 13 | + <Form layout="inline" name="addArticle" form={form} onFinish={onAddArticle}> |
| 14 | + <Form.Item name="name" rules={[{ required: true, message: 'Veuillez rentrer un nom d\'article' }]}> |
| 15 | + <Input placeholder="Nom de l'article"/> |
| 16 | + </Form.Item> |
| 17 | + <Form.Item name="price" rules={[{ required: true, message: 'Veuillez rentrer un prix' }]}> |
| 18 | + <InputNumber min={0} step={0.5} placeholder="Prix"/> |
| 19 | + </Form.Item> |
| 20 | + <Form.Item> |
| 21 | + <Button type="primary" htmlType="submit" className="button">Ajouter</Button> |
| 22 | + </Form.Item> |
| 23 | + </Form> |
| 24 | + <Divider/> |
| 25 | + <Flex gap={8} className="mt-4"> |
| 26 | + {items.length > 0 ? items.map((article) => ( |
| 27 | + <div key={article.id} className="flex bg-white rounded-md p-2 aspect-[1/1] w-28"> |
| 28 | + <Flex vertical justify="space-between" gap={8} className="w-full"> |
| 29 | + <Flex align="center" justify="space-between" className="w-full"> |
| 30 | + <Typography.Text strong> |
| 31 | + {article.name} |
| 32 | + </Typography.Text> |
| 33 | + <Button |
| 34 | + shape="circle" |
| 35 | + variant="filled" |
| 36 | + color="danger" |
| 37 | + size="small" |
| 38 | + icon={<CloseCircleOutlined/>} |
| 39 | + onClick={() => deleteArticle(article.id)} |
| 40 | + /> |
| 41 | + </Flex> |
| 42 | + <Typography.Text> |
| 43 | + {formattedPrice(article.price)} |
| 44 | + </Typography.Text> |
| 45 | + </Flex> |
| 46 | + </div> |
| 47 | + )) : <div>Aucun article créé</div>} |
| 48 | + </Flex> |
| 49 | + </Navigation> |
| 50 | + ); |
| 51 | +}; |
| 52 | + |
| 53 | +export default DashboardStore; |
0 commit comments