Modif Exercice 1 archi-separate-concerns#3
Conversation
| // components/OrderStatus.jsx | ||
| const OrderStatus = ({ status }) => { | ||
| let statusClass = "bg-blue-100 text-blue-800"; | ||
| if (status === "completed") statusClass = "bg-green-100 text-green-800"; | ||
| if (status === "processing") statusClass = "bg-yellow-100 text-yellow-800"; | ||
| return( <span | ||
| className={`px-2 inline-flex text-xs leading-5 font-semibold rounded-full | ||
| ${statusClass}`} | ||
| > | ||
| {status} | ||
| </span>) | ||
| } |
There was a problem hiding this comment.
Souvent on met les component enfant en dessous du parent
|
|
||
| if (!response.ok) { | ||
| throw new Error(data.message || 'Failed to send reminder'); | ||
| const {ok, data} = await api.post(`/api/orders/${orderId}/send-reminder`); |
There was a problem hiding this comment.
orderId need to be on the body part not as an id
| const updateOrders = (newOrders) => { | ||
| setOrders(newOrders); | ||
| }; |
There was a problem hiding this comment.
Autant faire passer directement le setOrders dans les params
| const {ok, data} = await api.post("/orders"); | ||
|
|
There was a problem hiding this comment.
comme on veut récupérer les orders,
const status = filter
c'est un post("/orders/search", {
status : filter
})
| const filteredOrders = orders.filter((order) => { | ||
| if (filter === "all") return true; | ||
| if (filter === "completed") return order.status === "completed"; | ||
| if (filter === "processing") return order.status === "processing"; | ||
| if (filter === "shipped") return order.status === "shipped"; | ||
| return true; | ||
| }); |
| const sortedOrders = [...filteredOrders].sort((a, b) => { | ||
| if (sortBy === "date") { | ||
| return new Date(b.date) - new Date(a.date); | ||
| } else if (sortBy === "total") { | ||
| return b.total - a.total; | ||
| } | ||
| return 0; | ||
| }); |
| const fetchStats = async () => { | ||
| try { | ||
| setLoading(true); | ||
| const { data, ok } = await api.get('/dashboard/stats'); | ||
|
|
||
| if (!ok) return toast.error("Failed to fetch stats"); | ||
|
|
||
| setStats(data); | ||
| setLoading(false); | ||
| } catch (err) { | ||
| setError(err.message); | ||
| setLoading(false); | ||
| } | ||
| }; |
There was a problem hiding this comment.
ici tu peux aussi faire un
finally {
setLoading(false)
}
en dessous du catch, ça te permet de mettre qu'une seule fois le setLoading.
(c'est du chipotage)
| const { data, ok } = await api.put(`/notifications/search`, { | ||
| id: notificationId, | ||
| read : true, |
There was a problem hiding this comment.
ici c'est un put donc y'a forcément un id dans le chemin (cf. workshop) donc pas besoin de mettre l'id dans le body
| const NotificationItem = ({ notifications, markAsRead }) => { | ||
| return ( | ||
| <> | ||
| {notifications.map(notification => ( | ||
| <div | ||
| key={notification.id} | ||
| className={`p-4 border-l-4 ${ | ||
| notification.read ? 'border-gray-300 bg-gray-50' : 'border-blue-500 bg-blue-50' | ||
| }`} | ||
| > | ||
| <div className="flex justify-between"> | ||
| <p className={`text-sm ${notification.read ? 'text-gray-600' : 'text-gray-900 font-semibold'}`}> | ||
| {notification.message} | ||
| </p> | ||
| {!notification.read && ( | ||
| <button | ||
| className="text-blue-500 text-xs hover:text-blue-700" | ||
| onClick={() => markAsRead(notification.id)} | ||
| > | ||
| Mark as read | ||
| </button> | ||
| )} | ||
| </div> | ||
| <p className="text-xs text-gray-500 mt-1"> | ||
| {new Date(notification.date).toLocaleString()} | ||
| </p> | ||
| </div> | ||
| ))} | ||
| </> | ||
| )}; |
There was a problem hiding this comment.
la t'as un composant avec aucun logique que du code html donc inutile
| const StatsCard = ({ icon, title, value, color }) => { | ||
| return ( | ||
| <div className="bg-white rounded-lg shadow p-6"> | ||
| <div className="flex items-center"> | ||
| <div className={`p-3 rounded-full ${color} mr-4`}> | ||
| {icon} | ||
| </div> | ||
| <div> | ||
| <p className="text-gray-500 text-sm">{title}</p> | ||
| <p className="text-2xl font-bold">{value}</p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| )}; |
There was a problem hiding this comment.
même chose ici aucune logique que du code html donc inutile
| createdBy: { | ||
| user_id: user._id, | ||
| name: user.name, |
There was a problem hiding this comment.
le createdBy dans le model dans mes souvenirs il a qu'un _id.
Si t'as pas changer le model tu peux donc pas ajouter ça comme ça
| // /comments est dans un query ducoup ? | ||
| router.put('/:id', async (req, res) => { | ||
| try { | ||
| const { text, user_id } = req.body; | ||
| const {user_id} = req.body; | ||
|
|
||
| const task = await Task.findById(req.params.id); | ||
| if (!task) { | ||
| return res.status(404).json({ error: 'Task not found' }); | ||
| return res.status(404).send({ ok: false, code: "TASK_NOT_FOUND" }); | ||
| } | ||
|
|
||
| const user = await User.findById(user_id); | ||
| if (!user) { | ||
| return res.status(404).json({ error: 'User not found' }); | ||
| return res.status(404).send({ ok: false, code: "USER_NOT_FOUND" }); | ||
| } | ||
| const comment = { |
There was a problem hiding this comment.
pas besoin d'un deuxième put ducoup ici
No description provided.