diff --git a/03_source/frontend/src/actions/party-event.ts b/03_source/frontend/src/actions/party-event.ts index 79add92..530bb1d 100644 --- a/03_source/frontend/src/actions/party-event.ts +++ b/03_source/frontend/src/actions/party-event.ts @@ -1,4 +1,4 @@ -// src/actions/product.ts +// src/actions/party-event.ts // import { useMemo } from 'react'; import axiosInstance, { endpoints, fetcher } from 'src/lib/axios'; @@ -74,6 +74,7 @@ type SearchResultsData = { results: IPartyEventItem[]; }; +// TODO: update useSearchPartyEvents export function useSearchProducts(query: string) { const url = query ? [endpoints.product.search, { params: { query } }] : ''; @@ -135,7 +136,6 @@ export async function updatePartyEvent(partyEventData: Partial) /** * Work in local */ - mutate( endpoints.partyEvent.list, (currentData: any) => { @@ -163,7 +163,6 @@ export async function deletePartyEvent(partyEventId: string) { /** * Work in local */ - mutate( endpoints.partyEvent.list, (currentData: any) => { diff --git a/03_source/frontend/src/actions/party-user.ts b/03_source/frontend/src/actions/party-user.ts index f1e24f2..42690d3 100644 --- a/03_source/frontend/src/actions/party-user.ts +++ b/03_source/frontend/src/actions/party-user.ts @@ -1,8 +1,9 @@ +// src/actions/party-user.ts +// import { useMemo } from 'react'; import axiosInstance, { endpoints, fetcher } from 'src/lib/axios'; import type { IPartyUserItem } from 'src/types/party-user'; import type { IProductItem } from 'src/types/product'; -import type { IUserItem } from 'src/types/user'; import type { SWRConfiguration } from 'swr'; import useSWR, { mutate } from 'swr'; @@ -16,15 +17,15 @@ const swrOptions: SWRConfiguration = { // ---------------------------------------------------------------------- -type UsersData = { - partyUsers: IUserItem[]; +type PartyUsersData = { + partyUsers: IPartyUserItem[]; }; // TODO: i want to refactor / tidy here export function useGetPartyUsers() { const url = endpoints.partyUser.list; - const { data, isLoading, error, isValidating } = useSWR(url, fetcher, swrOptions); + const { data, isLoading, error, isValidating } = useSWR(url, fetcher, swrOptions); const memoizedValue = useMemo( () => ({ @@ -72,6 +73,7 @@ type SearchResultsData = { results: IProductItem[]; }; +// TODO: update useSearchProducts export function useSearchProducts(query: string) { const url = query ? [endpoints.product.search, { params: { query } }] : ''; @@ -115,6 +117,33 @@ type SaveUserData = { password: string; }; +export async function createPartyUser(partyUserData: CreateUserData) { + /** + * Work on server + */ + const data = { partyUserData }; + const { + data: { id }, + } = await axiosInstance.post(endpoints.partyUser.create, data); + + /** + * Work in local + */ + mutate( + endpoints.partyUser.list, + (currentData: any) => { + const currentPartyUsers: IPartyUserItem[] = currentData?.partyUsers; + + const partyUsers = [...currentPartyUsers, { ...partyUserData, id }]; + + return { ...currentData, partyUsers }; + }, + false + ); +} + +// ---------------------------------------------------------------------- + export async function updatePartyUser(partyUserData: Partial) { /** * Work on server @@ -184,33 +213,6 @@ type CreateUserData = { password: string; }; -export async function createPartyUser(partyUserData: CreateUserData) { - /** - * Work on server - */ - const data = { partyUserData }; - const { - data: { id }, - } = await axiosInstance.post(endpoints.partyUser.create, data); - - /** - * Work in local - */ - mutate( - endpoints.partyUser.list, - (currentData: any) => { - const currentPartyUsers: IPartyUserItem[] = currentData?.partyUsers; - - const partyUsers = [...currentPartyUsers, { ...partyUserData, id }]; - - return { ...currentData, partyUsers }; - }, - false - ); -} - -// ---------------------------------------------------------------------- - export async function deletePartyUser(partyUserId: string) { /** * Work on server