feat: implement party user authentication system with signin/signup routes, JWT token validation, and frontend integration including mobile route configuration and API service updates
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// src/actions/party-user.ts
|
||||
// src/actions/party-user1.ts
|
||||
//
|
||||
import { useMemo } from 'react';
|
||||
import axiosInstance, { endpoints, fetcher } from 'src/lib/axios';
|
||||
@@ -21,7 +21,15 @@ type PartyUsersData = {
|
||||
partyUsers: IPartyUserItem[];
|
||||
};
|
||||
|
||||
// TODO: i want to refactor / tidy here
|
||||
/**
|
||||
* Fetches list of party users with SWR caching
|
||||
* @returns {Object} Contains:
|
||||
* - partyUsers: Array of party user items
|
||||
* - partyUsersLoading: Loading state
|
||||
* - partyUsersError: Error object if any
|
||||
* - partyUsersValidating: Validation state
|
||||
* - partyUsersEmpty: Boolean if no users found
|
||||
*/
|
||||
export function useGetPartyUsers() {
|
||||
const url = endpoints.partyUser.list;
|
||||
|
||||
@@ -73,7 +81,16 @@ type SearchResultsData = {
|
||||
results: IProductItem[];
|
||||
};
|
||||
|
||||
// TODO: update useSearchProducts
|
||||
/**
|
||||
* Searches products by query with SWR caching
|
||||
* @param {string} query - Search term
|
||||
* @returns {Object} Contains:
|
||||
* - searchResults: Array of matching products
|
||||
* - searchLoading: Loading state
|
||||
* - searchError: Error object if any
|
||||
* - searchValidating: Validation state
|
||||
* - searchEmpty: Boolean if no results found
|
||||
*/
|
||||
export function useSearchProducts(query: string) {
|
||||
const url = query ? [endpoints.product.search, { params: { query } }] : '';
|
||||
|
||||
@@ -117,6 +134,15 @@ type SaveUserData = {
|
||||
password: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new party user with optimistic UI updates
|
||||
* @param {CreateUserData} partyUserData - Data for the new party user
|
||||
* @returns {Promise<void>}
|
||||
* @sideeffects
|
||||
* - Makes POST request to create user on server
|
||||
* - Updates local SWR cache optimistically
|
||||
* - Triggers revalidation of party user list
|
||||
*/
|
||||
export async function createPartyUser(partyUserData: CreateUserData) {
|
||||
/**
|
||||
* Work on server
|
||||
@@ -144,6 +170,15 @@ export async function createPartyUser(partyUserData: CreateUserData) {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Updates party user data with optimistic UI updates
|
||||
* @param {Partial<IPartyUserItem>} partyUserData - Partial user data containing at least the ID
|
||||
* @returns {Promise<void>}
|
||||
* @sideeffects
|
||||
* - Makes PUT request to update user on server
|
||||
* - Updates both list and detail views in local SWR cache
|
||||
* - Preserves unchanged fields while updating modified ones
|
||||
*/
|
||||
export async function updatePartyUser(partyUserData: Partial<IPartyUserItem>) {
|
||||
/**
|
||||
* Work on server
|
||||
@@ -183,6 +218,14 @@ export async function updatePartyUser(partyUserData: Partial<IPartyUserItem>) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests connection to product API endpoint
|
||||
* @param {SaveUserData} saveUserData - User data object (currently unused)
|
||||
* @returns {Promise<AxiosResponse>} Response from test endpoint
|
||||
* @deprecated This function should be renamed to better reflect its purpose
|
||||
* TODO: Rename to testProductApiConnection() since it tests product API connection
|
||||
* TODO: Or implement actual image upload functionality if needed
|
||||
*/
|
||||
export async function uploadUserImage(saveUserData: SaveUserData) {
|
||||
console.log('uploadUserImage ?');
|
||||
// const url = userId ? [endpoints.user.details, { params: { userId } }] : '';
|
||||
@@ -213,6 +256,15 @@ type CreateUserData = {
|
||||
password: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Deletes a party user with optimistic UI updates
|
||||
* @param {string} partyUserId - ID of user to delete
|
||||
* @returns {Promise<void>}
|
||||
* @sideeffects
|
||||
* - Makes PATCH request to mark user as deleted on server
|
||||
* - Removes user from local SWR cache
|
||||
* - Triggers revalidation of party user list
|
||||
*/
|
||||
export async function deletePartyUser(partyUserId: string) {
|
||||
/**
|
||||
* Work on server
|
||||
|
Reference in New Issue
Block a user