diff --git a/front/app/containers/Admin/projects/project/phase/phaseParticipationConfig/index.tsx b/front/app/containers/Admin/projects/project/phase/phaseParticipationConfig/index.tsx index b0626e16c57a..33e9db1dc894 100644 --- a/front/app/containers/Admin/projects/project/phase/phaseParticipationConfig/index.tsx +++ b/front/app/containers/Admin/projects/project/phase/phaseParticipationConfig/index.tsx @@ -6,6 +6,7 @@ import { Input, IOption, } from '@citizenlab/cl2-component-library'; +import { pick } from 'lodash-es'; import { filter } from 'rxjs/operators'; import { CLErrors, Multiloc } from 'typings'; @@ -91,7 +92,13 @@ const PhaseParticipationConfig = ({ const { formatMessage } = useIntl(); const [participationConfig, setParticipationConfig] = useState( - phase ? phase.data.attributes : ideationDefaultConfig + // Only use the attributes from phase that are relevant to participation config + phase + ? (pick( + phase.data.attributes, + Object.keys(defaultParticipationConfig) + ) as IPhaseParticipationConfig) + : ideationDefaultConfig ); const [noLikingLimitError, setNoLikingLimitError] = diff --git a/front/app/containers/Admin/projects/project/phase/phaseParticipationConfig/utils/participationMethodConfigs.ts b/front/app/containers/Admin/projects/project/phase/phaseParticipationConfig/utils/participationMethodConfigs.ts index fa3ff97de374..62ac9d4f0ccd 100644 --- a/front/app/containers/Admin/projects/project/phase/phaseParticipationConfig/utils/participationMethodConfigs.ts +++ b/front/app/containers/Admin/projects/project/phase/phaseParticipationConfig/utils/participationMethodConfigs.ts @@ -34,10 +34,8 @@ export interface IPhaseParticipationConfig { document_annotation_embed_url?: string | null; } -export const defaultParticipationConfig: Omit< - IPhaseParticipationConfig, - 'participation_method' -> = { +export const defaultParticipationConfig: IPhaseParticipationConfig = { + participation_method: 'ideation', posting_enabled: true, commenting_enabled: true, reacting_enabled: true, diff --git a/front/app/containers/Admin/projects/project/timeline/edit.tsx b/front/app/containers/Admin/projects/project/timeline/edit.tsx index 4b174e9b703a..506d4fdcbf3e 100644 --- a/front/app/containers/Admin/projects/project/timeline/edit.tsx +++ b/front/app/containers/Admin/projects/project/timeline/edit.tsx @@ -140,20 +140,6 @@ const AdminPhaseEdit = () => { } }, [phaseFiles]); - const getAttributeDiff = useCallback( - ( - participationContextConfig: IPhaseParticipationConfig, - attributeDiff: IUpdatedPhaseProperties - ) => { - // Important to keep the order of the spread operators - return { - ...participationContextConfig, - ...attributeDiff, - }; - }, - [] - ); - const handlePhaseParticipationConfigChange = useCallback( (participationContextConfig: IPhaseParticipationConfig) => { const surveyCTALabel = tenantLocales?.reduce((acc, locale) => { @@ -173,8 +159,10 @@ const AdminPhaseEdit = () => { }, {}); setSubmitState('enabled'); + // Important to keep the order of the spread operators setAttributeDiff((attributeDiff) => ({ - ...getAttributeDiff(participationContextConfig, attributeDiff), + ...attributeDiff, + ...participationContextConfig, ...(participationContextConfig.participation_method === 'native_survey' && !attributeDiff.native_survey_button_multiloc && @@ -193,7 +181,6 @@ const AdminPhaseEdit = () => { formatMessageWithLocale, phase?.data.attributes.native_survey_button_multiloc, tenantLocales, - getAttributeDiff, ] ); @@ -311,11 +298,11 @@ const AdminPhaseEdit = () => { const handlePhaseParticipationConfigSubmit = ( participationContextConfig: IPhaseParticipationConfig ) => { - const newAttributeDiff = getAttributeDiff( - participationContextConfig, - attributeDiff - ); - save(projectId, phase?.data, newAttributeDiff); + // Important to keep the order of the spread operators + save(projectId, phase?.data, { + ...attributeDiff, + ...participationContextConfig, + }); }; const handleError = (error: { errors: CLErrors }) => {