diff --git a/Makefile b/Makefile index 241334c..864d9e9 100644 --- a/Makefile +++ b/Makefile @@ -64,5 +64,6 @@ check-api: poetry run ruff format . --check regenerate-openapi-local: - rm client/src/types/openapi-types.ts \ - npx openapi-typescript http://localhost:8000/openapi -o client/src/types/openapi-types.ts + cd client \ + rm src/types/openapi-types.ts \ + npx openapi-typescript http://localhost:8000/openapi -o src/types/openapi-types.ts diff --git a/client/src/api/api.ts b/client/src/api/api.ts index 37824a7..1fef22c 100644 --- a/client/src/api/api.ts +++ b/client/src/api/api.ts @@ -4,7 +4,7 @@ import axiosRetry from 'axios-retry'; import { Auth, Tokens } from '@/types/auth'; import { useAuthStore } from '@/store/authStore'; import { AuthService } from '@/services/authService'; -import { User } from '@/types/user'; +import { User, UserUpdate } from '@/types/user'; const baseURL = `${import.meta.env.VITE_APP_HTTP_PROTOCOL}://${ import.meta.env.VITE_APP_API_URL @@ -114,6 +114,11 @@ const api = { const response = await base.get(`/account/${userId}`); return response.data; }, + + async createUser(user: UserUpdate): Promise { + const response = await base.post('/account', user); + return response.data; + }, }; export default api; diff --git a/client/src/components/UserCreate.tsx b/client/src/components/UserCreate.tsx index a2db419..9ddc6a6 100644 --- a/client/src/components/UserCreate.tsx +++ b/client/src/components/UserCreate.tsx @@ -12,6 +12,8 @@ import { import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useUserSelector } from '@/store/userStore'; +import { UserUpdate } from '@/types/user'; +import { UserService } from '@/services/userService'; const { Option } = Select; @@ -25,7 +27,11 @@ const getBase64 = (file: FileType): Promise => reader.onerror = (error) => reject(error); }); -export default function UserCreate() { +interface UserCreateProps { + closeDrawer: () => void; +} + +export default function UserCreate({ closeDrawer }: UserCreateProps) { const user = useUserSelector(); const { t } = useTranslation(); const [previewOpen, setPreviewOpen] = useState(false); @@ -45,6 +51,12 @@ export default function UserCreate() { const handleChange: UploadProps['onChange'] = ({ fileList: newFileList }) => setFileList(newFileList); + const onFinish = async (values: UserUpdate) => { + console.log(values); + await UserService.createUser(values); + closeDrawer(); + }; + const customUploadButton = (
{ @@ -160,11 +161,12 @@ export default function AccountsPage() { } /> - + { @@ -23,4 +23,10 @@ export class UserService { const user = api.getUserById(userId); return user; } + + static async createUser(user: UserUpdate): Promise { + console.log('createUser'); + const createdUser = api.createUser(user); + return createdUser; + } } diff --git a/client/src/types/openapi-types.ts b/client/src/types/openapi-types.ts index 1e14c6c..79eb692 100644 --- a/client/src/types/openapi-types.ts +++ b/client/src/types/openapi-types.ts @@ -193,6 +193,8 @@ export interface components { amountPages: number; /** Currentpage */ currentPage: number; + /** Limit */ + limit: number; }; /** Auth */ Auth: { diff --git a/client/src/types/user.ts b/client/src/types/user.ts index ef49e4a..1251ddf 100644 --- a/client/src/types/user.ts +++ b/client/src/types/user.ts @@ -1,8 +1,8 @@ -import { components } from "./openapi-types"; +import { components } from './openapi-types'; export type User = components['schemas']['User']; export type AllUserResponse = components['schemas']['AllUserResponse']; export type AllUser = components['schemas']['AllUser']; export type AccountStatus = components['schemas']['AccountStatus']; export type AccountRole = components['schemas']['AccountRole']; - +export type UserUpdate = components['schemas']['UserUpdate'];