From f54b8fa49a145a548be50f7c12e49f33ddb5293d Mon Sep 17 00:00:00 2001 From: Iva Date: Tue, 24 Oct 2023 12:38:11 +0300 Subject: [PATCH] Implement for initiatives --- .../InitiativeForm/SubmitButtonBar.tsx | 8 +++- front/app/components/InitiativeForm/index.tsx | 46 +++++++++++++++---- .../containers/UsersEditPage/ProfileForm.tsx | 7 ++- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/front/app/components/InitiativeForm/SubmitButtonBar.tsx b/front/app/components/InitiativeForm/SubmitButtonBar.tsx index 528197817bec..7fe8d6948d49 100644 --- a/front/app/components/InitiativeForm/SubmitButtonBar.tsx +++ b/front/app/components/InitiativeForm/SubmitButtonBar.tsx @@ -51,9 +51,14 @@ const SubmitFooterInner = styled.div` interface FormSubmitFooterProps { processing: boolean; className?: string; + onClick?: () => void; } -const SubmitButtonBar = ({ className, processing }: FormSubmitFooterProps) => { +const SubmitButtonBar = ({ + className, + processing, + onClick, +}: FormSubmitFooterProps) => { const theme = useTheme(); const initiativeReviewRequired = useInitiativeReviewRequired(); @@ -69,6 +74,7 @@ const SubmitButtonBar = ({ className, processing }: FormSubmitFooterProps) => { textColor="#FFF" type="submit" processing={processing} + onClick={onClick} > import('./ProfileVisibilityFormSection') ); @@ -37,9 +38,7 @@ const AnonymousParticipationConfirmationModal = lazy( ); import LocationInput from 'components/HookForm/LocationInput'; import { Box } from '@citizenlab/cl2-component-library'; -const ImageAndAttachmentsSection = lazy( - () => import('./ImagesAndAttachmentsSection') -); +import ImageAndAttachmentsSection from './ImagesAndAttachmentsSection'; import Warning from 'components/UI/Warning'; // Hooks @@ -51,6 +50,7 @@ import useInitiativeReviewRequired from 'containers/InitiativesShow/hooks/useIni import { stripHtmlTags, isNilOrError } from 'utils/helperUtils'; import useInitiativeCosponsorsRequired from 'containers/InitiativesShow/hooks/useInitiativeCosponsorsRequired'; import useAppConfiguration from 'api/app_configuration/useAppConfiguration'; +import ContentUploadDisclaimer from 'components/ContentUploadDisclaimer'; import { useSearchParams } from 'react-router-dom'; import { reverseGeocode } from 'utils/locationTools'; @@ -91,6 +91,7 @@ const InitiativeForm = ({ const locale = useLocale(); const [search] = useSearchParams(); const { formatMessage } = useIntl(); + const [isDisclaimerOpened, setIsDisclaimerOpened] = useState(false); const [showAnonymousConfirmationModal, setShowAnonymousConfirmationModal] = useState(false); const cosponsorsRequired = useInitiativeCosponsorsRequired(); @@ -237,13 +238,34 @@ const InitiativeForm = ({ } }; + const handleDisclaimer = () => { + const disclamerNeeded = + methods.getValues('images')?.[0] || + methods.getValues('header_bg')?.[0] || + methods.getValues('local_initiative_files')?.length > 0 || + Object.values(methods.getValues('body_multiloc')).some((value) => + value.includes(' { + methods.handleSubmit(onFormSubmit)(); + setIsDisclaimerOpened(false); + }; + + const onCancelDisclaimer = () => { + setIsDisclaimerOpened(false); + }; + return ( <> -
+ @@ -329,7 +351,15 @@ const InitiativeForm = ({ /> - + +
diff --git a/front/app/containers/UsersEditPage/ProfileForm.tsx b/front/app/containers/UsersEditPage/ProfileForm.tsx index 1c580c8c76f7..9881b8640264 100644 --- a/front/app/containers/UsersEditPage/ProfileForm.tsx +++ b/front/app/containers/UsersEditPage/ProfileForm.tsx @@ -44,6 +44,7 @@ import useFeatureFlag from 'hooks/useFeatureFlag'; import useAppConfigurationLocales from 'hooks/useAppConfigurationLocales'; import onboardingCampaignsKeys from 'api/onboarding_campaigns/keys'; import { queryClient } from 'utils/cl-react-query/queryClient'; +import { isEmpty } from 'lodash-es'; const StyledIconTooltip = styled(IconTooltip)` margin-left: 5px; @@ -130,7 +131,11 @@ const ProfileForm = () => { })); const handleDisclaimer = () => { - if (methods.formState.dirtyFields.avatar && methods.getValues('avatar')) { + if ( + methods.formState.dirtyFields.avatar && + methods.getValues('avatar') && + isEmpty(methods.formState.errors) + ) { setIsDisclaimerOpened(true); } else { methods.handleSubmit(onFormSubmit)();