-
Notifications
You must be signed in to change notification settings - Fork 6
Modif Exercice 1 archi-separate-concerns #3
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
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orderId need to be on the body part not as an id
const updateOrders = (newOrders) => { | ||
setOrders(newOrders); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Autant faire passer directement le setOrders dans les params
const {ok, data} = await api.post("/orders"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bannir
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; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Côté back aussi
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pas besoin d'un deuxième put ducoup ici
No description provided.