diff --git a/src/frontend/apps/desk/src/features/auth/api/getMe.tsx b/src/frontend/apps/desk/src/features/auth/api/getMe.tsx index 9e6992e..4c02c27 100644 --- a/src/frontend/apps/desk/src/features/auth/api/getMe.tsx +++ b/src/frontend/apps/desk/src/features/auth/api/getMe.tsx @@ -1,16 +1,6 @@ import { fetchAPI } from '@/api'; -/** - * Represents user data retrieved from the API. - * This interface is incomplete, and will be - * refactored in a near future. - * - * @interface UserData - * @property {string} email - The email of the user. - */ -export interface UserData { - email: string; -} +import { User } from './types'; /** * Asynchronously retrieves the current user's data from the API. @@ -20,12 +10,12 @@ export interface UserData { * @async * @function getMe * @throws {Error} Throws an error if the API request fails. - * @returns {Promise} A promise that resolves to the user data. + * @returns {Promise} A promise that resolves to the user data. */ -export const getMe = async (): Promise => { +export const getMe = async (): Promise => { const response = await fetchAPI(`users/me/`); if (!response.ok) { throw new Error(`Couldn't fetch user data: ${response.statusText}`); } - return response.json() as Promise; + return response.json() as Promise; }; diff --git a/src/frontend/apps/desk/src/features/auth/api/index.ts b/src/frontend/apps/desk/src/features/auth/api/index.ts index e2faeac..d81520d 100644 --- a/src/frontend/apps/desk/src/features/auth/api/index.ts +++ b/src/frontend/apps/desk/src/features/auth/api/index.ts @@ -1 +1,2 @@ export * from './getMe'; +export * from './types'; diff --git a/src/frontend/apps/desk/src/features/auth/api/types.ts b/src/frontend/apps/desk/src/features/auth/api/types.ts new file mode 100644 index 0000000..b383621 --- /dev/null +++ b/src/frontend/apps/desk/src/features/auth/api/types.ts @@ -0,0 +1,12 @@ +/** + * Represents user retrieved from the API. + * @interface User + * @property {string} id - The id of the user. + * @property {string} email - The email of the user. + * @property {string} name - The name of the user. + */ +export interface User { + id: string; + email: string; + name?: string; +} diff --git a/src/frontend/apps/desk/src/features/auth/index.ts b/src/frontend/apps/desk/src/features/auth/index.ts index c66c026..b04f47a 100644 --- a/src/frontend/apps/desk/src/features/auth/index.ts +++ b/src/frontend/apps/desk/src/features/auth/index.ts @@ -1,2 +1,3 @@ export * from './Auth'; export * from './useAuthStore'; +export * from './api/types'; diff --git a/src/frontend/apps/desk/src/features/auth/useAuthStore.tsx b/src/frontend/apps/desk/src/features/auth/useAuthStore.tsx index 3da8d07..5d0bbed 100644 --- a/src/frontend/apps/desk/src/features/auth/useAuthStore.tsx +++ b/src/frontend/apps/desk/src/features/auth/useAuthStore.tsx @@ -1,6 +1,6 @@ import { create } from 'zustand'; -import { UserData, getMe } from '@/features/auth/api'; +import { User, getMe } from '@/features/auth/api'; export const login = () => { window.location.replace( @@ -12,7 +12,7 @@ interface AuthStore { authenticated: boolean; initAuth: () => void; logout: () => void; - userData?: UserData; + userData?: User; } const initialState = { @@ -26,7 +26,7 @@ export const useAuthStore = create((set) => ({ initAuth: () => { getMe() - .then((data: UserData) => { + .then((data: User) => { set({ authenticated: true, userData: data }); }) .catch(() => { diff --git a/src/frontend/apps/desk/src/features/teams/api/types.tsx b/src/frontend/apps/desk/src/features/teams/api/types.tsx index d72bd47..22f19ca 100644 --- a/src/frontend/apps/desk/src/features/teams/api/types.tsx +++ b/src/frontend/apps/desk/src/features/teams/api/types.tsx @@ -1,3 +1,5 @@ +import { User } from '@/features/auth/'; + export enum Role { MEMBER = 'member', ADMIN = 'administrator', @@ -8,6 +10,13 @@ export interface Access { id: string; role: Role; user: User; + abilities: { + delete: boolean; + get: boolean; + patch: boolean; + put: boolean; + set_role_to: Role[]; + }; } export interface Team { @@ -16,10 +25,11 @@ export interface Team { accesses: Access[]; created_at: string; updated_at: string; -} - -export interface User { - id: string; - email: string; - name?: string; + abilities: { + delete: boolean; + get: boolean; + manage_accesses: boolean; + patch: boolean; + put: boolean; + }; }