From b5e58ef4273970d1e5f6d4e8c9478870711b948e Mon Sep 17 00:00:00 2001 From: Roie Natan Date: Wed, 20 Sep 2023 16:43:36 +0300 Subject: [PATCH] call governance/space-name --- .../useCases/useCommonUpdate.ts | 33 ++++++++++++++++--- .../interfaces/UpdateGovernanceCircleName.ts | 8 +++-- src/pages/OldCommon/store/actions.tsx | 14 ++++++++ src/pages/OldCommon/store/constants.tsx | 4 +++ src/pages/OldCommon/store/saga.tsx | 29 ++++++++++++++++ .../components/CreationForm/types.ts | 2 +- .../utils/generateValidationSchema.ts | 4 +++ .../ProjectCreationForm/configuration.ts | 6 +--- .../Form/Formik/RolesArray/RolesArray.tsx | 6 ++-- .../RolesArrayWrapper/RolesArrayWrapper.tsx | 2 +- 10 files changed, 92 insertions(+), 16 deletions(-) diff --git a/src/pages/OldCommon/components/CommonListContainer/EditCommonModal/useCases/useCommonUpdate.ts b/src/pages/OldCommon/components/CommonListContainer/EditCommonModal/useCases/useCommonUpdate.ts index 37b27828e2..175f55326c 100644 --- a/src/pages/OldCommon/components/CommonListContainer/EditCommonModal/useCases/useCommonUpdate.ts +++ b/src/pages/OldCommon/components/CommonListContainer/EditCommonModal/useCases/useCommonUpdate.ts @@ -1,5 +1,7 @@ import { useCallback, useState } from "react"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; +import { selectUser } from "@/pages/Auth/store/selectors"; +import { UpdateGovernanceCircleNamePayload } from "@/pages/OldCommon/interfaces/UpdateGovernanceCircleName"; import { FileService, Logger } from "@/services"; import { isRequestError } from "@/services/Api"; import { ErrorCode } from "@/shared/constants"; @@ -11,7 +13,10 @@ import { UpdateCommonData, UpdateCommonPayload, } from "../../../../interfaces"; -import { updateCommon as updateCommonAction } from "../../../../store/actions"; +import { + updateCommon as updateCommonAction, + updateGovernanceCircleName, +} from "../../../../store/actions"; interface Return { isCommonUpdateLoading: boolean; @@ -54,6 +59,7 @@ const useCommonUpdate = (commonId?: string): Return => { const [common, setCommon] = useState(null); const [error, setError] = useState(""); const dispatch = useDispatch(); + const user = useSelector(selectUser()); const updateCommon = useCallback( async (updatedData: IntermediateUpdateCommonData) => { @@ -61,8 +67,6 @@ const useCommonUpdate = (commonId?: string): Return => { return; } - console.log(updatedData); - setIsCommonUpdateLoading(true); try { @@ -112,6 +116,27 @@ const useCommonUpdate = (commonId?: string): Return => { }, }), ); + + if (user?.uid && updatedData.roles) { + const circles = updatedData.roles.map((role) => ({ + circleId: role.circleId, + newName: role.circleName, + })); + const payload: UpdateGovernanceCircleNamePayload = { + commonId, + userId: user.uid, + changes: circles, + }; + + dispatch( + updateGovernanceCircleName.request({ + payload, + callback: (error, updatedGovernance) => { + console.log(updatedGovernance); + }, + }), + ); + } } catch (err) { Logger.error(error); setError(getErrorMessage(err, updatedData.name)); diff --git a/src/pages/OldCommon/interfaces/UpdateGovernanceCircleName.ts b/src/pages/OldCommon/interfaces/UpdateGovernanceCircleName.ts index 7fc262088d..128a932ebf 100644 --- a/src/pages/OldCommon/interfaces/UpdateGovernanceCircleName.ts +++ b/src/pages/OldCommon/interfaces/UpdateGovernanceCircleName.ts @@ -1,6 +1,10 @@ +interface NewCircle { + circleId: string; + newName: string; +} + export interface UpdateGovernanceCircleNamePayload { commonId: string; - circleId: string; userId: string; - newName: string; + changes: NewCircle[]; } diff --git a/src/pages/OldCommon/store/actions.tsx b/src/pages/OldCommon/store/actions.tsx index 7cd3e45156..983af2fac1 100644 --- a/src/pages/OldCommon/store/actions.tsx +++ b/src/pages/OldCommon/store/actions.tsx @@ -44,6 +44,7 @@ import { ImmediateContributionResponse, } from "../interfaces"; import { UpdateDiscussionMessageDto } from "../interfaces/UpdateDiscussionMessageDto"; +import { UpdateGovernanceCircleNamePayload } from "../interfaces/UpdateGovernanceCircleName"; import { CommonsActionTypes } from "./constants"; export const createGovernance = createAsyncAction( @@ -369,6 +370,19 @@ export const updateGovernanceRules = createAsyncAction( Error >(); +export const updateGovernanceCircleName = createAsyncAction( + CommonsActionTypes.UPDATE_GOVERNANCE_CIRCLE_NAME, + CommonsActionTypes.UPDATE_GOVERNANCE_CIRCLE_NAME_SUCCESS, + CommonsActionTypes.UPDATE_GOVERNANCE_CIRCLE_NAME_FAILURE, +)< + { + payload: UpdateGovernanceCircleNamePayload; + callback: (error: Error | null, governance?: Governance) => void; + }, + Common, + Error +>(); + export const createVote = createAsyncAction( CommonsActionTypes.CREATE_VOTE, CommonsActionTypes.CREATE_VOTE_SUCCESS, diff --git a/src/pages/OldCommon/store/constants.tsx b/src/pages/OldCommon/store/constants.tsx index 7ab2203521..692a6f377e 100644 --- a/src/pages/OldCommon/store/constants.tsx +++ b/src/pages/OldCommon/store/constants.tsx @@ -214,4 +214,8 @@ export enum CommonsActionTypes { UPDATE_GOVERNANCE_RULES = "@COMMONS/UPDATE_GOVERNANCE_RULES", UPDATE_GOVERNANCE_RULES_SUCCESS = "@COMMONS/UPDATE_GOVERNANCE_RULES_SUCCESS", UPDATE_GOVERNANCE_RULES_FAILURE = "@COMMONS/UPDATE_GOVERNANCE_RULES_FAILURE", + + UPDATE_GOVERNANCE_CIRCLE_NAME = "@COMMONS/UPDATE_GOVERNANCE_CIRCLE_NAME", + UPDATE_GOVERNANCE_CIRCLE_NAME_SUCCESS = "@COMMONS/UPDATE_GOVERNANCE_CIRCLE_NAME_SUCCESS", + UPDATE_GOVERNANCE_CIRCLE_NAME_FAILURE = "@COMMONS/UPDATE_GOVERNANCE_CIRCLE_NAME_FAILURE", } diff --git a/src/pages/OldCommon/store/saga.tsx b/src/pages/OldCommon/store/saga.tsx index b1c51a42fa..1b407893bb 100644 --- a/src/pages/OldCommon/store/saga.tsx +++ b/src/pages/OldCommon/store/saga.tsx @@ -42,6 +42,7 @@ import { createCommon as createCommonApi, updateCommon as updateCommonApi, updateGovernanceRules as updateGovernanceRulesApi, + updateGovernanceCircleName as updateGovernanceCircleNameApi, createProposal as createProposalApi, fetchCommonList, fetchCommonDetail, @@ -1692,6 +1693,30 @@ export function* updateGovernanceRules( } } +export function* updateGovernanceCircleName( + action: ReturnType, +): Generator { + try { + const updatedCircles = (yield call( + updateGovernanceCircleNameApi, + action.payload.payload, + )) as Awaited>; + + console.log(updatedCircles); + // const updatedGovernance = { + // ...action.payload.governance, + // unstructuredRules: updatedRules.unstructuredRules, + // } as Governance; + + // yield put(actions.getGovernance.success(updatedGovernance)); + // action.payload.callback(null, updatedGovernance); + } catch (error) { + if (isError(error)) { + action.payload.callback(error); + } + } +} + export function* commonsSaga() { yield takeLatest(actions.createGovernance.request, createGovernance); yield takeLatest(actions.getCommonsList.request, getCommonsList); @@ -1699,6 +1724,10 @@ export function* commonsSaga() { actions.updateGovernanceRules.request, updateGovernanceRules, ); + yield takeLatest( + actions.updateGovernanceCircleName.request, + updateGovernanceCircleName, + ); yield takeLatest(actions.getCommonsListByIds.request, getCommonsListByIds); yield takeLatest(actions.getCommonDetail.request, getCommonDetail); yield takeLatest( diff --git a/src/pages/commonCreation/components/CreationForm/types.ts b/src/pages/commonCreation/components/CreationForm/types.ts index 1e21bb0713..c86330cd93 100644 --- a/src/pages/commonCreation/components/CreationForm/types.ts +++ b/src/pages/commonCreation/components/CreationForm/types.ts @@ -58,7 +58,7 @@ export interface LinksFormItem extends BaseFormItem { export interface RolesFormItem extends BaseFormItem { type: CreationFormItemType.Roles; - validation?: Pick; + validation?: Pick; } export type CreationFormItem = diff --git a/src/pages/commonCreation/components/CreationForm/utils/generateValidationSchema.ts b/src/pages/commonCreation/components/CreationForm/utils/generateValidationSchema.ts index 46ac024e15..37afe2dde8 100644 --- a/src/pages/commonCreation/components/CreationForm/utils/generateValidationSchema.ts +++ b/src/pages/commonCreation/components/CreationForm/utils/generateValidationSchema.ts @@ -6,6 +6,7 @@ import { LinksFormItem, TextFieldFormItem, UploadFilesFormItem, + RolesFormItem, } from "../types"; type Schema = Yup.Schema; @@ -97,6 +98,9 @@ export const generateValidationSchema = ( if (item.type === CreationFormItemType.Links) { schema = getValidationSchemaForLinksItem(item); } + // if (item.type === CreationFormItemType.Roles) { + // schema = getValidationSchemaForTextFieldItem(item); + // } return schema ? { diff --git a/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/configuration.ts b/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/configuration.ts index 1596cd12ff..118bedcf33 100644 --- a/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/configuration.ts +++ b/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/configuration.ts @@ -120,11 +120,7 @@ export const getConfiguration = ( validation: { required: { value: true, - message: "Role title required", - }, - max: { - value: MAX_ROLE_TITLE_LENGTH, - message: "Role title is too long", + message: "Role name is required", }, }, }); diff --git a/src/shared/components/Form/Formik/RolesArray/RolesArray.tsx b/src/shared/components/Form/Formik/RolesArray/RolesArray.tsx index cb1adabfc4..03e7e65841 100644 --- a/src/shared/components/Form/Formik/RolesArray/RolesArray.tsx +++ b/src/shared/components/Form/Formik/RolesArray/RolesArray.tsx @@ -5,13 +5,13 @@ import { FormikErrors, FormikTouched, } from "formik"; -import { Roles } from "@/shared/models"; +import { Role, Roles } from "@/shared/models"; import { ErrorText } from "../../ErrorText"; import { TextField } from "../TextField"; import styles from "./RolesArray.module.scss"; type Errors = string | string[] | FormikErrors | undefined; -type Touched = FormikTouched[] | undefined; +type Touched = FormikTouched[] | undefined; export interface RolesArrayProps extends FieldArrayConfig { values: Roles; @@ -55,7 +55,7 @@ const RolesArray: FC = (props) => { value={role.circleName} placeholder="Role title" /> - {!role && Error} + {/* {errors && {errors}} */} ); })} diff --git a/src/shared/components/Form/Formik/RolesArrayWrapper/RolesArrayWrapper.tsx b/src/shared/components/Form/Formik/RolesArrayWrapper/RolesArrayWrapper.tsx index 927c672a0a..e2f0176924 100644 --- a/src/shared/components/Form/Formik/RolesArrayWrapper/RolesArrayWrapper.tsx +++ b/src/shared/components/Form/Formik/RolesArrayWrapper/RolesArrayWrapper.tsx @@ -18,7 +18,7 @@ const RolesArrayWrapper: FC = (props) => { {...props} values={value} errors={error} - touched={formik.touched[props.name] as FormikTouched[]} + touched={formik.touched[props.name] as FormikTouched[]} /> ); };