From 6c2102e9deb83923425269177a75a0e09b4d5819 Mon Sep 17 00:00:00 2001 From: G Date: Mon, 1 Jul 2024 17:23:14 +0000 Subject: [PATCH] fix somes types typo around naming convention. ex : firstName -> first_name --- src/contexts/UserAuthenticationContext.tsx | 26 +++++++++++++++++--------- src/hooks/useTransactionsHistory.tsx | 34 ++++++++++++++++++++++++++++++++-- src/screens/UserProfileScreen.tsx | 8 +++++--- src/utils/requests/types.ts | 12 ++++++++---- 4 files changed, 62 insertions(+), 18 deletions(-) diff --git a/src/contexts/UserAuthenticationContext.tsx b/src/contexts/UserAuthenticationContext.tsx index 8a94a52..5cc23df 100644 --- a/src/contexts/UserAuthenticationContext.tsx +++ b/src/contexts/UserAuthenticationContext.tsx @@ -16,16 +16,20 @@ export const UserAuthenticationContext = createContext + first_name: "", + // biome-ignore lint/style/useNamingConvention: + last_name: "", marchand: { - // biome-ignore lint/style/useNamingConvention: + // biome-ignore lint/style/useNamingConvention: marchand_id: "", nom: "", code: "", adresse: "", - urlSuccess: "", - urlEchec: "", + // biome-ignore lint/style/useNamingConvention: + url_success: "", + // biome-ignore lint/style/useNamingConvention: + url_echec: "", entreprise: 0, user: 0, }, @@ -42,16 +46,20 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac const [userInformations, setUserInformations] = useState({ username: "JohnDoe", email: "JohnDoe@example.com", - firstName: "John", - lastName: "Doe", + // biome-ignore lint/style/useNamingConvention: + first_name: "John", + // biome-ignore lint/style/useNamingConvention: + last_name: "Doe", marchand: { // biome-ignore lint/style/useNamingConvention: marchand_id: "id123", nom: "Beasy", code: "BEASY-EXAMPLE-1", adresse: "Plateau 2, 1023, Immeuble Chardy", - urlSuccess: "https://example.com/success", - urlEchec: "https://example.com/echec", + // biome-ignore lint/style/useNamingConvention: + url_success: "https://example.com/success", + // biome-ignore lint/style/useNamingConvention: + url_echec: "https://example.com/echec", entreprise: 0, user: 0, }, diff --git a/src/hooks/useTransactionsHistory.tsx b/src/hooks/useTransactionsHistory.tsx index 3c537fe..7f5db7b 100644 --- a/src/hooks/useTransactionsHistory.tsx +++ b/src/hooks/useTransactionsHistory.tsx @@ -42,10 +42,40 @@ const useTransactionsHistory = () => { }, [data], ); + + const filterDataByReference = (data: Transaction[], reference: string) => { + if (!data?.length) return []; + + return data.filter( + (transaction) => transaction.reference.includes(reference) && transaction.reference, + ); + }; + + const filterByOperators = (data: Transaction[]) => { + if (!data?.length) return []; + // create a set + const set = new Set(); + + for (const key of Object.keys(operatorsFilter)) { + if (operatorsFilter[key as keyof OperatorsFilter]) { + set.add(key as PaymentCode); + } + } + return data.filter((transaction) => { + // return true if the set is empty, as there is no need to check + if (set.size === 0) return true; + // return true if the set contains the value + return set.has(transaction.type_paiement_label); + }); + }; + const transactionsHistory: Transaction[] = useMemo(() => { if (!data) return []; - return filterByReference(referenceFilter); - }, [data, filterByReference, referenceFilter]); + const filteredByOperators = filterByOperators(data); + const filteredByReference = filterDataByReference(filteredByOperators, referenceFilter); + return filteredByReference; + // return filterByReference(referenceFilter); + }, [data, referenceFilter, filterByOperators, filterDataByReference]); return { transactionsHistory, diff --git a/src/screens/UserProfileScreen.tsx b/src/screens/UserProfileScreen.tsx index f462732..a850133 100644 --- a/src/screens/UserProfileScreen.tsx +++ b/src/screens/UserProfileScreen.tsx @@ -45,7 +45,7 @@ const UserProfileScreen = () => { - {userInformations.firstName} {userInformations.lastName} + {userInformations.first_name} {userInformations.last_name} {userInformations.email} @@ -138,7 +138,9 @@ const UserProfileScreen = () => { Url succès - {userInformations.marchand.urlSuccess} + + {userInformations.marchand.url_success} + { Url échec - {userInformations.marchand.urlEchec} + {userInformations.marchand.url_echec} diff --git a/src/utils/requests/types.ts b/src/utils/requests/types.ts index 63dff92..b591738 100644 --- a/src/utils/requests/types.ts +++ b/src/utils/requests/types.ts @@ -19,8 +19,10 @@ export interface ImerchandInformations { nom: string; code: string; adresse: string; - urlSuccess: string; - urlEchec: string; + // biome-ignore lint/style/useNamingConvention: + url_success: string; + // biome-ignore lint/style/useNamingConvention: + url_echec: string; entreprise: number; user: number; } @@ -28,7 +30,9 @@ export interface ImerchandInformations { export interface IuserInformations { username: string; email: string; - firstName: string; - lastName: string; + // biome-ignore lint/style/useNamingConvention: + first_name: string; + // biome-ignore lint/style/useNamingConvention: + last_name: string; marchand: ImerchandInformations; } -- libgit2 0.27.1