From efe12849e473255a42f870274469df128bc4f678 Mon Sep 17 00:00:00 2001 From: Maric Diranovic Date: Tue, 11 Feb 2025 17:30:50 +0100 Subject: [PATCH] feat: Project edition --- client/src/containers/cards/component.tsx | 2 +- .../my-projects/sidebar/projectDetails.tsx | 33 +++++--- client/src/hooks/my-projects/index.ts | 21 ++++++ .../my-projects/[projectId]/edit/index.tsx | 40 ++++++++++ client/src/pages/my-projects/new/layout.tsx | 2 +- client/src/store/index.ts | 2 + client/src/store/myProjects/form/index.ts | 75 +++++++++++++++++++ 7 files changed, 162 insertions(+), 13 deletions(-) create mode 100644 client/src/pages/my-projects/[projectId]/edit/index.tsx create mode 100644 client/src/store/myProjects/form/index.ts diff --git a/client/src/containers/cards/component.tsx b/client/src/containers/cards/component.tsx index 726d5c0f..812660c8 100644 --- a/client/src/containers/cards/component.tsx +++ b/client/src/containers/cards/component.tsx @@ -36,7 +36,7 @@ const Cards = ({ data = [], theme = 'grey', pathname, project = false }: CardsPr )} {data.map((item) => ( - + ))} ); diff --git a/client/src/containers/my-projects/sidebar/projectDetails.tsx b/client/src/containers/my-projects/sidebar/projectDetails.tsx index c829321e..4d3e5fdd 100644 --- a/client/src/containers/my-projects/sidebar/projectDetails.tsx +++ b/client/src/containers/my-projects/sidebar/projectDetails.tsx @@ -8,8 +8,13 @@ import CHEVRON_RIGHT from 'svgs/icons/arrow-right.svg?sprite'; import LOCK from 'svgs/icons/lock.svg?sprite'; import USER_TWO from 'svgs/icons/user-two.svg?sprite'; import { useDispatch } from 'react-redux'; +import { Field } from 'react-final-form'; +import { Placement } from '@floating-ui/react-dom-interactions'; +import { useAppSelector } from 'store/hooks'; +import { RootState } from 'store'; const ProjectDetails = () => { const [logo, setLogo] = useState(null); + const draft = useAppSelector((state: RootState) => state['/projectForm']) const dispatch = useDispatch(); @@ -48,17 +53,20 @@ const ProjectDetails = () => { -
-
@@ -67,12 +75,15 @@ const ProjectDetails = () => { - + + - {/* Upload Logo */} +
- +
- + ); } diff --git a/client/src/store/index.ts b/client/src/store/index.ts index 45c24666..e0b3fe53 100644 --- a/client/src/store/index.ts +++ b/client/src/store/index.ts @@ -6,6 +6,7 @@ import myProjects from 'store/myProjects'; import { configureStore, combineReducers } from '@reduxjs/toolkit'; import type { ReducersMapObject } from '@reduxjs/toolkit'; import { createWrapper } from 'next-redux-wrapper'; +import ProjectFormReducer from 'store/myProjects/form'; const staticReducers = { '/action-map': actionMap, @@ -13,6 +14,7 @@ const staticReducers = { '/projects': projects, '/dashboards/general-report': dashboardsGeneralReport, '/myProjects': myProjects, + '/projectForm': ProjectFormReducer, }; const asyncReducers = {}; diff --git a/client/src/store/myProjects/form/index.ts b/client/src/store/myProjects/form/index.ts new file mode 100644 index 00000000..2b991247 --- /dev/null +++ b/client/src/store/myProjects/form/index.ts @@ -0,0 +1,75 @@ +import { createSlice, PayloadAction } from '@reduxjs/toolkit'; +import { HYDRATE } from 'next-redux-wrapper'; +import { STORE_WRAPPER } from 'store'; +import qs from 'query-string'; + +export interface ProjectFormState { + draftProject: { + name: string; + description: string; + logo: File | null; + contact_first_name: string; + contact_last_name: string; + website: string; + country_id: number | null; + state_id: number | null; + city: string; + leadership_demographics_other: string; + recipient_legal_status: string; + leadership_demographics: string[]; + } +} + +const initialState: ProjectFormState = { + draftProject:{ + name: '', + description: '', + logo: null, + contact_first_name: '', + contact_last_name: '', + website: '', + country_id: null, + state_id: null, + city: '', + leadership_demographics_other: '', + recipient_legal_status: '', + leadership_demographics: [], + } + +}; + +const slice = createSlice({ + name: '/createProjectForm', + initialState, + reducers: { + // updateField: ( + // state: ProjectFormState, + // action: PayloadAction<{ field: K; value: ProjectFormState[K] }> + // ) => { + // state[action.payload.field] = action.payload.value; + // }, + // setForm: (state, action: PayloadAction) => { + // return action.payload; + // }, + + updateDraft: (state, action: PayloadAction>) => { + state.draftProject = { ...state.draftProject, ...action.payload }; + }, + + clearDraft: (state) => { + state.draftProject = initialState.draftProject; + } + }, + extraReducers: { + [HYDRATE]: (state, action) => { + return { + ...state, + ...action.payload['/createProjectForm'], + }; + }, + }, +}); + +export const { updateDraft, clearDraft } = slice.actions; + +export default slice.reducer;