From 11cc94697f45a7bb600cae3138e3d932f1055a56 Mon Sep 17 00:00:00 2001 From: Xavier Le Cunff Date: Wed, 8 Jan 2025 10:29:32 +0100 Subject: [PATCH] feat: take reviews --- .../identityCheck/api/useCreditActivation.ts | 4 ++-- .../pages/profile/store/addressStore.ts | 8 ++++++-- .../identityCheck/pages/profile/store/cityStore.ts | 10 +++++++--- .../identityCheck/pages/profile/store/nameStore.ts | 4 ++-- .../SingleFilterBannerContainer.native.test.tsx | 2 +- src/features/venueMap/store/initialVenuesStore.ts | 8 ++++++-- src/features/venueMap/store/selectedVenueStore.ts | 13 +++++-------- src/features/venueMap/store/venueTypeCodeStore.ts | 2 +- src/features/venueMap/store/venuesFilterStore.ts | 12 ++++++------ src/features/venueMap/store/venuesStore.ts | 6 +++--- src/libs/store/createActions.ts | 9 ++++++--- src/libs/store/createStore.ts | 9 +++++++-- 12 files changed, 52 insertions(+), 35 deletions(-) diff --git a/src/features/identityCheck/api/useCreditActivation.ts b/src/features/identityCheck/api/useCreditActivation.ts index 43c33155b47..8d26f83265a 100644 --- a/src/features/identityCheck/api/useCreditActivation.ts +++ b/src/features/identityCheck/api/useCreditActivation.ts @@ -9,8 +9,8 @@ const defaultState: CreditState = { activationDate: undefined, } -const useCreditStore = createStore('credit', defaultState, { persist: true }) +const useCreditStore = createStore({ name: 'credit', defaultState, options: { persist: true } }) export const creditActions = createActions(useCreditStore, (set) => ({ - setActivationDate: (date: Date) => set({ activationDate: date }), + setActivationDate: (activationDate: Date) => set({ activationDate }), })) diff --git a/src/features/identityCheck/pages/profile/store/addressStore.ts b/src/features/identityCheck/pages/profile/store/addressStore.ts index d6b879583d1..0355db0f0b3 100644 --- a/src/features/identityCheck/pages/profile/store/addressStore.ts +++ b/src/features/identityCheck/pages/profile/store/addressStore.ts @@ -7,10 +7,14 @@ type State = { const defaultState: State = { address: null } -const useAddressStore = createStore('profile-address', defaultState, { persist: true }) +const useAddressStore = createStore({ + name: 'profile-address', + defaultState, + options: { persist: true }, +}) export const addressActions = createActions(useAddressStore, (set) => ({ - setAddress: (payload: string) => set({ address: payload }), + setAddress: (address: string) => set({ address }), resetAddress: () => set(defaultState), })) diff --git a/src/features/identityCheck/pages/profile/store/cityStore.ts b/src/features/identityCheck/pages/profile/store/cityStore.ts index 864f48941a9..0dc860cac9d 100644 --- a/src/features/identityCheck/pages/profile/store/cityStore.ts +++ b/src/features/identityCheck/pages/profile/store/cityStore.ts @@ -6,13 +6,17 @@ type State = { city: SuggestedCity | null } const defaultState: State = { city: null } -const useCityStore = createStore('profile-city', defaultState, { - persist: true, +const useCityStore = createStore({ + name: 'profile-city', + defaultState, + options: { + persist: true, + }, }) export const useCity = () => useCityStore((state) => state.city) export const cityActions = createActions(useCityStore, (set) => ({ - setCity: (payload: SuggestedCity) => set({ city: payload }), + setCity: (city: SuggestedCity) => set({ city }), resetCity: () => set(defaultState), })) diff --git a/src/features/identityCheck/pages/profile/store/nameStore.ts b/src/features/identityCheck/pages/profile/store/nameStore.ts index d8c966f2dc7..5f835bfc31b 100644 --- a/src/features/identityCheck/pages/profile/store/nameStore.ts +++ b/src/features/identityCheck/pages/profile/store/nameStore.ts @@ -10,11 +10,11 @@ type State = { name: Name | null } const defaultState: State = { name: null } -const useNameStore = createStore('profile-name', defaultState, { persist: true }) +const useNameStore = createStore({ name: 'profile-name', defaultState, options: { persist: true } }) export const useName = () => useNameStore((state) => state.name) export const nameActions = createActions(useNameStore, (set) => ({ - setName: (payload: Name) => set({ name: payload }), + setName: (name: Name) => set({ name }), resetName: () => set(defaultState), })) diff --git a/src/features/venueMap/components/FilterBannerContainer/SingleFilterBannerContainer.native.test.tsx b/src/features/venueMap/components/FilterBannerContainer/SingleFilterBannerContainer.native.test.tsx index d3aa973e5d7..4fdec2d059d 100644 --- a/src/features/venueMap/components/FilterBannerContainer/SingleFilterBannerContainer.native.test.tsx +++ b/src/features/venueMap/components/FilterBannerContainer/SingleFilterBannerContainer.native.test.tsx @@ -9,7 +9,7 @@ import { render, screen } from 'tests/utils' import { SingleFilterBannerContainer } from './SingleFilterBannerContainer' jest.mock('features/venueMap/store/venueTypeCodeStore') -const mockUseVenueTypeCode = useVenueTypeCode as jest.Mock +const mockUseVenueTypeCode = useVenueTypeCode const VENUE_TYPE = VenueTypeCodeKey.MOVIE diff --git a/src/features/venueMap/store/initialVenuesStore.ts b/src/features/venueMap/store/initialVenuesStore.ts index b03c8d7367d..5a33859bcb7 100644 --- a/src/features/venueMap/store/initialVenuesStore.ts +++ b/src/features/venueMap/store/initialVenuesStore.ts @@ -8,10 +8,14 @@ type State = { const defaultState: State = { initialVenues: [] } -const useInitialVenuesStore = createStore('venue-map-store', defaultState, { persist: true }) +const useInitialVenuesStore = createStore({ + name: 'venue-map-store', + defaultState, + options: { persist: true }, +}) export const useInitialVenues = () => useInitialVenuesStore((state) => state.initialVenues) export const initialVenuesActions = createActions(useInitialVenuesStore, (set) => ({ - setInitialVenues: (payload: Venue[]) => set({ initialVenues: payload }), + setInitialVenues: (initialVenues: Venue[]) => set({ initialVenues }), })) diff --git a/src/features/venueMap/store/selectedVenueStore.ts b/src/features/venueMap/store/selectedVenueStore.ts index a8f49a74781..a7873612664 100644 --- a/src/features/venueMap/store/selectedVenueStore.ts +++ b/src/features/venueMap/store/selectedVenueStore.ts @@ -8,14 +8,11 @@ type State = { const defaultState: State = { selectedVenue: null } -const useSelectedVenueStore = createStore('venue-map-selected-venue', defaultState) +const useSelectedVenueStore = createStore({ name: 'venue-map-selected-venue', defaultState }) export const useSelectedVenue = () => useSelectedVenueStore((state) => state.selectedVenue) -export const selectedVenueActions = createActions( - useSelectedVenueStore, - (set: (payload: State) => void) => ({ - setSelectedVenue: (payload: GeolocatedVenue) => set({ selectedVenue: payload }), - removeSelectedVenue: () => set(defaultState), - }) -) +export const selectedVenueActions = createActions(useSelectedVenueStore, (set) => ({ + setSelectedVenue: (selectedVenue: GeolocatedVenue) => set({ selectedVenue }), + removeSelectedVenue: () => set(defaultState), +})) diff --git a/src/features/venueMap/store/venueTypeCodeStore.ts b/src/features/venueMap/store/venueTypeCodeStore.ts index 2dd27a05a07..692226a11a6 100644 --- a/src/features/venueMap/store/venueTypeCodeStore.ts +++ b/src/features/venueMap/store/venueTypeCodeStore.ts @@ -8,7 +8,7 @@ type State = { const defaultState: State = { venueTypeCode: null } -const useVenueTypeCodeStore = createStore('venue-map-venue-type-code', defaultState) +const useVenueTypeCodeStore = createStore({ name: 'venue-map-venue-type-code', defaultState }) export const useVenueTypeCode = () => useVenueTypeCodeStore((state) => state.venueTypeCode) export const venueTypeCodeActions = createActions(useVenueTypeCodeStore, (set) => ({ diff --git a/src/features/venueMap/store/venuesFilterStore.ts b/src/features/venueMap/store/venuesFilterStore.ts index 4b38ca65ced..c334c945c78 100644 --- a/src/features/venueMap/store/venuesFilterStore.ts +++ b/src/features/venueMap/store/venuesFilterStore.ts @@ -12,19 +12,19 @@ const defaultState: State = { venuesFilters: [], } -const useVenuesFilterStore = createStore('venue-VenuesFilterilter', defaultState) +const useVenuesFilterStore = createStore({ name: 'venue-filter', defaultState }) export const useVenuesFilter = () => useVenuesFilterStore((state) => state.venuesFilters) export const venuesFilterActions = createActions(useVenuesFilterStore, (set) => ({ - setVenuesFilters: (payload: VenueTypeCodeKey[]) => set((_) => ({ venuesFilters: payload })), - addVenuesFilters: (payload: VenueTypeCodeKey[]) => + setVenuesFilters: (venuesFilters: VenueTypeCodeKey[]) => set((_) => ({ venuesFilters })), + addVenuesFilters: (VenueTypeCodeKeys: VenueTypeCodeKey[]) => set((state: State) => ({ - venuesFilters: Array.from(new Set([...state.venuesFilters, ...payload])), + venuesFilters: Array.from(new Set([...state.venuesFilters, ...VenueTypeCodeKeys])), })), - removeVenuesFilters: (payload: VenueTypeCodeKey[]) => + removeVenuesFilters: (VenueTypeCodeKeys: VenueTypeCodeKey[]) => set((state: State) => ({ - venuesFilters: difference(state.venuesFilters, payload), + venuesFilters: difference(state.venuesFilters, VenueTypeCodeKeys), })), reset: () => set((_) => ({ venuesFilters: [] })), })) diff --git a/src/features/venueMap/store/venuesStore.ts b/src/features/venueMap/store/venuesStore.ts index 6b71f4e0f92..f8ad0201793 100644 --- a/src/features/venueMap/store/venuesStore.ts +++ b/src/features/venueMap/store/venuesStore.ts @@ -8,10 +8,10 @@ type State = { const defaultState: State = { venues: [] } -const useVenuesStore = createStore('venue-map-venues', defaultState) +const useVenuesStore = createStore({ name: 'venue-map-venues', defaultState }) export const useVenues = () => useVenuesStore((state) => state.venues) -export const venuesActions = createActions(useVenuesStore, (set: (payload: State) => void) => ({ - setVenues: (payload: Venue[]) => set({ venues: payload }), +export const venuesActions = createActions(useVenuesStore, (set) => ({ + setVenues: (venues: Venue[]) => set({ venues }), })) diff --git a/src/libs/store/createActions.ts b/src/libs/store/createActions.ts index 4d99a3a5fb2..4fd9ee286ad 100644 --- a/src/libs/store/createActions.ts +++ b/src/libs/store/createActions.ts @@ -4,10 +4,13 @@ type Store = UseBoundStore> type Actions = (set: Store['setState']) => ActionsType -// eslint-disable-next-line @typescript-eslint/no-explicit-any -- we don't want to restrict the payload type -export const createActions = void>>( +export const createActions = < + State, + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- we don't want to restrict the payload type + ActionsType extends Record void>, +>( store: Store, actions: Actions -): ActionsType => { +): Readonly => { return actions(store.setState) } diff --git a/src/libs/store/createStore.ts b/src/libs/store/createStore.ts index 38eb5675e5d..abcbcfcd911 100644 --- a/src/libs/store/createStore.ts +++ b/src/libs/store/createStore.ts @@ -7,8 +7,13 @@ type Options = { persist?: boolean } -// eslint-disable-next-line @typescript-eslint/no-explicit-any -- we don't want to restrict the payload type -export const createStore = (name: string, defaultState: State, options?: Options) => { +type Params = { + name: string + defaultState: State + options?: Options +} + +export const createStore = ({ name, defaultState, options }: Params) => { const store = () => defaultState const persistedStore = persist(store, { name,