diff --git a/src/client/index.ts b/src/client/index.ts index bde18fe..28621ce 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -12,6 +12,8 @@ export type { AuthLoginResponse } from './models/AuthLoginResponse'; export type { DealChangeStatusRequest } from './models/DealChangeStatusRequest'; export type { DealChangeStatusResponse } from './models/DealChangeStatusResponse'; export type { DealCreateRequest } from './models/DealCreateRequest'; +export type { DealCreateResponse } from './models/DealCreateResponse'; +export type { DealQuickCreateRequest } from './models/DealQuickCreateRequest'; export type { HTTPValidationError } from './models/HTTPValidationError'; export type { ValidationError } from './models/ValidationError'; diff --git a/src/client/services/DealService.ts b/src/client/services/DealService.ts index b5286ba..f6e66ca 100644 --- a/src/client/services/DealService.ts +++ b/src/client/services/DealService.ts @@ -5,6 +5,8 @@ import type { DealChangeStatusRequest } from '../models/DealChangeStatusRequest'; import type { DealChangeStatusResponse } from '../models/DealChangeStatusResponse'; import type { DealCreateRequest } from '../models/DealCreateRequest'; +import type { DealCreateResponse } from '../models/DealCreateResponse'; +import type { DealQuickCreateRequest } from '../models/DealQuickCreateRequest'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; @@ -29,6 +31,26 @@ export class DealService { }, }); } + /** + * Quick Create + * @returns DealCreateResponse Successful Response + * @throws ApiError + */ + public static quickCreateDealQuickCreatePost({ + requestBody, + }: { + requestBody: DealQuickCreateRequest, + }): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/deal/quickCreate', + body: requestBody, + mediaType: 'application/json', + errors: { + 422: `Validation Error`, + }, + }); + } /** * Change Status * @returns DealChangeStatusResponse Successful Response diff --git a/src/components/Dnd/CreateDealButton/CreateDealButton.tsx b/src/components/Dnd/CreateDealButton/CreateDealButton.tsx index 1e222bb..60b88dc 100644 --- a/src/components/Dnd/CreateDealButton/CreateDealButton.tsx +++ b/src/components/Dnd/CreateDealButton/CreateDealButton.tsx @@ -1,30 +1,53 @@ import {FC, useState} from "react"; import styles from './CreateDealButton.module.css'; -import {Button, rem, Text, TextInput, Transition} from '@mantine/core'; +import {Text, Transition} from '@mantine/core'; import CreateDealFrom from "../CreateDealForm/CreateDealFrom.tsx"; +import {DealService} from "../../../client"; +import {dateWithoutTimezone} from "../../../shared/lib/utils.ts"; type Props = { onClick: () => void; } const CreateDealButton: FC = ({onClick}) => { const [isCreating, setIsCreating] = useState(false); - + const [isTransitionEnded, setIsTransitionEnded] = useState(true); return (
{ if (isCreating) return; setIsCreating(prevState => !prevState) + setIsTransitionEnded(false); }} > + {(!isCreating && isTransitionEnded) && + Быстрое добавление + } + setIsTransitionEnded(true)} + > + {(styles) => ( +
+ { + setIsCreating(false) + }} + onSubmit={(quickDeal) => { + console.log(quickDeal); + DealService.quickCreateDealQuickCreatePost({ + requestBody: { + ...quickDeal, + acceptance_date: dateWithoutTimezone(quickDeal.acceptance_date) + } + }) + }} + /> +
+ )} +
- Быстрое добавление - { - }} - onSubmit={() => { - }} - />
) } diff --git a/src/components/Dnd/CreateDealForm/CreateDealFrom.tsx b/src/components/Dnd/CreateDealForm/CreateDealFrom.tsx index 1b09937..1f8651d 100644 --- a/src/components/Dnd/CreateDealForm/CreateDealFrom.tsx +++ b/src/components/Dnd/CreateDealForm/CreateDealFrom.tsx @@ -14,8 +14,8 @@ const CreateDealFrom: FC = ({onSubmit, onCancel}) => { const form = useForm({ initialValues: { name: '', - clientName: '', - clientAddress: '', + client_name: '', + client_address: '', comment: '', acceptance_date: new Date() } @@ -23,7 +23,7 @@ const CreateDealFrom: FC = ({onSubmit, onCancel}) => { return (
console.log(values))} + onSubmit={form.onSubmit((values) => onSubmit(values))} >
= ({onSubmit, onCancel}) => {
{ - }}/> + nameRestProps={form.getInputProps('client_name')} + addressRestProps={form.getInputProps('client_address')} + />
@@ -61,6 +60,7 @@ const CreateDealFrom: FC = ({onSubmit, onCancel}) => {
diff --git a/src/components/Selects/ClientSelect/ClientSelect.tsx b/src/components/Selects/ClientSelect/ClientSelect.tsx index 66441cc..b2a5cd4 100644 --- a/src/components/Selects/ClientSelect/ClientSelect.tsx +++ b/src/components/Selects/ClientSelect/ClientSelect.tsx @@ -74,7 +74,7 @@ const ClientSelect: FC = ({onSelect, addressRestProps, nameRestProps, wit {withAddress && { selectClient(prevState => prevState && {...prevState, address: event.target.value}) }} diff --git a/src/features/uiSlice.ts b/src/features/uiSlice.ts new file mode 100644 index 0000000..07ef4b2 --- /dev/null +++ b/src/features/uiSlice.ts @@ -0,0 +1,23 @@ +import {createSlice, PayloadAction} from "@reduxjs/toolkit"; + +interface UIState { + isLoading: boolean; +} + +const initialState: UIState = { + isLoading: false +} + +const uiSlice = createSlice({ + name: 'ui', + initialState, + reducers: { + setIsLoading: (state, action: PayloadAction) => { + state.isLoading = action.payload; + } + } + } +) + +export default uiSlice.reducer; +export const {setIsLoading} = uiSlice.actions; \ No newline at end of file diff --git a/src/pages/LeadsPage/ui/LeadsPage.tsx b/src/pages/LeadsPage/ui/LeadsPage.tsx index 07099fd..24829ea 100644 --- a/src/pages/LeadsPage/ui/LeadsPage.tsx +++ b/src/pages/LeadsPage/ui/LeadsPage.tsx @@ -1,42 +1,49 @@ -import {FC} from "react"; +import {FC, useEffect} from "react"; import styles from './LeadsPage.module.css'; import Board from "../../../components/Dnd/Board/Board.tsx"; import {Button, TextInput} from "@mantine/core"; import {DragDropContext} from "@hello-pangea/dnd"; -import ClientSelect from "../../../components/Selects/ClientSelect/ClientSelect.tsx"; -import {DateTimePicker} from "@mantine/dates"; +import {useAppDispatch} from "../../../redux/store.ts"; +import {setIsLoading} from "../../../features/uiSlice.ts"; export const LeadsPage: FC = () => { + const dispatch = useAppDispatch(); + + useEffect(() => { + dispatch(setIsLoading(true)); + }, []); return ( -
-
+ <> +
+
+ + +
+
+ { + }}> + + + + + - - + + +
-
- { - }}> - - - - - + - - -
-
) } diff --git a/src/pages/RootPage/RootPage.tsx b/src/pages/RootPage/RootPage.tsx index ca33fa3..2a3883e 100644 --- a/src/pages/RootPage/RootPage.tsx +++ b/src/pages/RootPage/RootPage.tsx @@ -4,9 +4,11 @@ import {useSelector} from "react-redux"; import {RootState} from "../../redux/store.ts"; import {OpenAPI} from "../../client"; import PageWrapper from "../PageWrapper/PageWrapper.tsx"; +import {LoadingOverlay} from "@mantine/core"; const RootPage = () => { const authState = useSelector((state: RootState) => state.auth); + const uiState = useSelector((state: RootState) => state.ui); const rewriteLocalStorage = () => { const jsonData = JSON.stringify(authState); localStorage.setItem('authState', jsonData); @@ -21,13 +23,11 @@ const RootPage = () => { return ( <> - + - - ) } diff --git a/src/redux/store.ts b/src/redux/store.ts index 8ffe6ef..e9f4297 100644 --- a/src/redux/store.ts +++ b/src/redux/store.ts @@ -1,10 +1,12 @@ import {configureStore} from "@reduxjs/toolkit"; import {useDispatch} from "react-redux"; import authReducer from '../features/authSlice'; +import uiReducer from '../features/uiSlice'; export const store = configureStore({ reducer: { - auth: authReducer + auth: authReducer, + ui: uiReducer } }); diff --git a/src/shared/lib/utils.ts b/src/shared/lib/utils.ts new file mode 100644 index 0000000..4a938c8 --- /dev/null +++ b/src/shared/lib/utils.ts @@ -0,0 +1,7 @@ +export const dateWithoutTimezone = (date: Date) => { + const tzoffset = date.getTimezoneOffset() * 60000; //offset in milliseconds + const withoutTimezone = new Date(date.valueOf() - tzoffset) + .toISOString() + .slice(0, -1); + return withoutTimezone; +}; \ No newline at end of file diff --git a/src/types/QuickDeal.ts b/src/types/QuickDeal.ts index a598313..560d348 100644 --- a/src/types/QuickDeal.ts +++ b/src/types/QuickDeal.ts @@ -1,8 +1,7 @@ -import {Client} from "./Client.ts"; - export type QuickDeal = { - name: string; - client: Client - comment: string; - acceptance_date: string; + name: string + client_name: string + client_address: string + comment:string + acceptance_date: Date } \ No newline at end of file