refactor: add explicit any types and improve readability in group state handling

- Updated `setProject` function in `page.tsx` to include explicit `(prev: any)` and `(group: any)` type annotations for better readability.
- Added `"use client";` directive to `notifications.tsx` for React server-client compatibility.
- Improved structural consistency and clarity in group and person state updates.
This commit is contained in:
Mathis H (Avnyr) 2025-05-16 17:05:07 +02:00
parent 2851fb3dfa
commit 6cc6506e6f
2 changed files with 13 additions and 11 deletions

View File

@ -156,7 +156,7 @@ export default function ProjectGroupsPage() {
if (data.action === "created" && data.group) { if (data.action === "created" && data.group) {
// Add the new group to the list // Add the new group to the list
setProject(prev => ({ setProject((prev: any) => ({
...prev, ...prev,
groups: [...prev.groups, data.group] groups: [...prev.groups, data.group]
})); }));
@ -179,9 +179,9 @@ export default function ProjectGroupsPage() {
if (data.action === "updated" && data.group) { if (data.action === "updated" && data.group) {
// Update the group in the list // Update the group in the list
setProject(prev => ({ setProject((prev: any) => ({
...prev, ...prev,
groups: prev.groups.map(group => groups: prev.groups.map((group: any) =>
group.id === data.group.id ? data.group : group group.id === data.group.id ? data.group : group
) )
})); }));
@ -189,9 +189,9 @@ export default function ProjectGroupsPage() {
toast.info(`Groupe mis à jour: ${data.group.name}`); toast.info(`Groupe mis à jour: ${data.group.name}`);
} else if (data.action === "deleted" && data.group) { } else if (data.action === "deleted" && data.group) {
// Remove the group from the list // Remove the group from the list
setProject(prev => ({ setProject((prev: any) => ({
...prev, ...prev,
groups: prev.groups.filter(group => group.id !== data.group.id) groups: prev.groups.filter((group: any) => group.id !== data.group.id)
})); }));
toast.info(`Groupe supprimé: ${data.group.name}`); toast.info(`Groupe supprimé: ${data.group.name}`);
@ -212,9 +212,9 @@ export default function ProjectGroupsPage() {
if (data.group && data.person) { if (data.group && data.person) {
// Update the group with the new person // Update the group with the new person
setProject(prev => ({ setProject((prev: any) => ({
...prev, ...prev,
groups: prev.groups.map(group => { groups: prev.groups.map((group: any) => {
if (group.id === data.group.id) { if (group.id === data.group.id) {
return { return {
...group, ...group,
@ -243,13 +243,13 @@ export default function ProjectGroupsPage() {
if (data.group && data.person) { if (data.group && data.person) {
// Update the group by removing the person // Update the group by removing the person
setProject(prev => ({ setProject((prev: any) => ({
...prev, ...prev,
groups: prev.groups.map(group => { groups: prev.groups.map((group: any) => {
if (group.id === data.group.id) { if (group.id === data.group.id) {
return { return {
...group, ...group,
persons: group.persons.filter(person => person.id !== data.person.id) persons: group.persons.filter((person: any) => person.id !== data.person.id)
}; };
} }
return group; return group;

View File

@ -1,3 +1,5 @@
"use client";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useSocket } from "@/lib/socket-context"; import { useSocket } from "@/lib/socket-context";
import { toast } from "sonner"; import { toast } from "sonner";