Remove CharacterComponent and CharacterDetail components
- Deleted `CharacterComponent` and `CharacterDetail` files from the project. - Refactored related logic to improve code maintainability and reduce redundancy.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import type {Context, Dispatch, JSX, ReactNode, SetStateAction} from 'react';
|
||||
import {createContext, useCallback, useState} from 'react';
|
||||
import React, {createContext, useCallback, useState} from 'react';
|
||||
import AlertStack from '@/components/AlertStack';
|
||||
import {cleanErrorMessage} from '@/lib/errors';
|
||||
|
||||
@@ -38,10 +38,11 @@ export const AlertContext: Context<AlertContextProps> = createContext<AlertConte
|
||||
export function AlertProvider({children}: AlertProviderProps): JSX.Element {
|
||||
const [alerts, setAlerts]: [Alert[], Dispatch<SetStateAction<Alert[]>>] = useState<Alert[]>([]);
|
||||
|
||||
const addAlert: (type: AlertType, message: string) => void = useCallback((type: AlertType, message: string): void => {
|
||||
const addAlert: (type: AlertType, message: string) => void = useCallback((type: AlertType, message: unknown): void => {
|
||||
const safeMessage: string = typeof message === 'string' ? message : String(message ?? 'Une erreur est survenue');
|
||||
const id: string = `${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
|
||||
const newAlert: Alert = {id, type, message};
|
||||
|
||||
const newAlert: Alert = {id, type, message: safeMessage};
|
||||
|
||||
setAlerts((prev: Alert[]): Alert[] => [...prev, newAlert]);
|
||||
}, []);
|
||||
|
||||
@@ -54,7 +55,7 @@ export function AlertProvider({children}: AlertProviderProps): JSX.Element {
|
||||
}, [addAlert]);
|
||||
|
||||
const errorMessage: (message: string) => void = useCallback((message: string): void => {
|
||||
addAlert('error', cleanErrorMessage(message));
|
||||
addAlert('error', message);
|
||||
}, [addAlert]);
|
||||
|
||||
const infoMessage: (message: string) => void = useCallback((message: string): void => {
|
||||
|
||||
Reference in New Issue
Block a user