Skip to content

Commit

Permalink
Add delete functionality for community guidelines (#7284)
Browse files Browse the repository at this point in the history
  • Loading branch information
reactoholic authored Dec 6, 2024
1 parent 24b3ad7 commit f04b698
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 65 deletions.
6 changes: 3 additions & 3 deletions src/core/i18n/en/translation.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,7 @@
"LICENSE_MANAGER": "License Manager",
"BETA_TESTER": "Beta Tester",
"VC_CAMPAIGN": "VC Early Access"
},
"removeContent": "Delete Community Guidelines"
}
},
"community": {
"memberUsers": "Member Users ({{count}})",
Expand Down Expand Up @@ -631,7 +630,8 @@
"confirmationDialog": {
"title": "Updating Community Guidelines",
"description": "Are you sure you want to replace your existing Community Guidelines? This action cannot be undone."
}
},
"deleteCommunityGuidelines": "Delete Community Guidelines"
},
"applicationsHelp": "Here you can find everyone that applied to become a member of this Space. By clicking on them you can review their application and accept or reject them.",
"applicationStatus": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ interface CommunityGuidelinesContainerProvided {
communityGuidelinesId: string | undefined;
profileId: string | undefined; // ProfileId is required to create references
loading: boolean;
removeCommunityGuidelinesContentLoading: boolean;
onSelectCommunityGuidelinesTemplate: (template: Identifiable) => Promise<unknown>;
onUpdateCommunityGuidelines: (values: CommunityGuidelines) => Promise<unknown>;
onDeleteAndSaveContent?: () => void;
onDeleteCommunityGuidelinesContent?: () => Promise<unknown>;
}

interface CommunityGuidelinesContainerProps extends SimpleContainerProps<CommunityGuidelinesContainerProvided> {
Expand Down Expand Up @@ -64,8 +63,7 @@ const CommunityGuidelinesContainer = ({ communityId, children }: CommunityGuidel
const communityGuidelinesId = communityGuidelines?.id;
const profileId = data?.lookup.community?.guidelines.profile.id;

const [removeCommunityGuidelinesContent, { loading: removeCommunityGuidelinesContentLoading }] =
useRemoveCommunityGuidelinesContentMutation();
const [removeCommunityGuidelinesContent] = useRemoveCommunityGuidelinesContentMutation();
const [updateGuidelines, { loading: submittingGuidelines }] = useUpdateCommunityGuidelinesMutation();

const onUpdateCommunityGuidelines = async (values: CommunityGuidelines) => {
Expand Down Expand Up @@ -99,7 +97,7 @@ const CommunityGuidelinesContainer = ({ communityId, children }: CommunityGuidel
});
};

const onDeleteAndSaveContent = async () => {
const onDeleteCommunityGuidelinesContent = async () => {
if (!communityGuidelinesId) {
return;
}
Expand Down Expand Up @@ -188,11 +186,10 @@ const CommunityGuidelinesContainer = ({ communityId, children }: CommunityGuidel
communityGuidelines,
communityGuidelinesId,
profileId,
removeCommunityGuidelinesContentLoading,
loading: loading || submittingGuidelines || removingReference || addingReference,
onUpdateCommunityGuidelines,
onSelectCommunityGuidelinesTemplate,
onDeleteAndSaveContent,
onDeleteCommunityGuidelinesContent,
})}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ import { referenceSegmentSchema } from '@/domain/platform/admin/components/Commo
import LoadingButton from '@mui/lab/LoadingButton';
import ProfileReferenceSegment from '@/domain/platform/admin/components/Common/ProfileReferenceSegment';
import ConfirmationDialog from '@/core/ui/dialogs/ConfirmationDialog';
import useLoadingState from '@/domain/shared/utils/useLoadingState';

type CommunityGuidelinesFormProps = {
data: FormValues | undefined;
profileId: string | undefined;
onSubmit: (values: FormValues) => void;
loading?: boolean;
disabled?: boolean;
removeCommunityGuidelinesContentLoading?: boolean;
hasDeleteContentButton?: boolean;
onDeleteAndSaveContent?: () => void;
onDeleteCommunityGuidelines?: () => Promise<unknown>;
};

type FormValues = {
Expand All @@ -47,12 +46,13 @@ const CommunityGuidelinesForm = ({
onSubmit,
disabled,
loading,
hasDeleteContentButton = false,
removeCommunityGuidelinesContentLoading,
onDeleteAndSaveContent,
onDeleteCommunityGuidelines,
}: CommunityGuidelinesFormProps) => {
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);

const hasDeleteContentsButton =
Boolean(data?.displayName) || Boolean(data?.description) || Number(data?.references.length) > 0;

const { t } = useTranslation();

const initialValues: FormValues = {
Expand All @@ -61,6 +61,10 @@ const CommunityGuidelinesForm = ({
references: data?.references ?? [],
};

const [handleDeleteCommunityGuidelines, deleteCommunityGuidelinesLoading] = useLoadingState(async () => {
await onDeleteCommunityGuidelines?.();
});

return (
<>
<Formik initialValues={initialValues} validationSchema={validationSchema} enableReinitialize onSubmit={onSubmit}>
Expand All @@ -84,14 +88,14 @@ const CommunityGuidelinesForm = ({
<ProfileReferenceSegment references={values.references} profileId={profileId} />

<Box display="flex" marginY={4} gap={1} justifyContent="flex-end">
{hasDeleteContentButton && (
{hasDeleteContentsButton && (
<LoadingButton
loading={loading}
variant="outlined"
disabled={!isValid}
onClick={() => setDeleteDialogOpen(true)}
>
{t('common.removeContent')}
{t('community.communityGuidelines.deleteCommunityGuidelines')}
</LoadingButton>
)}

Expand All @@ -114,14 +118,14 @@ const CommunityGuidelinesForm = ({
show: deleteDialogOpen,
}}
actions={{
onConfirm: () => {
onDeleteAndSaveContent?.();
onConfirm: async () => {
await handleDeleteCommunityGuidelines();
setDeleteDialogOpen(false);
},
onCancel: () => setDeleteDialogOpen(false),
}}
state={{
isLoading: Boolean(removeCommunityGuidelinesContentLoading),
isLoading: deleteCommunityGuidelinesLoading,
}}
/>
</>
Expand Down
12 changes: 2 additions & 10 deletions src/domain/journey/space/pages/AdminSpaceCommunityPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,10 @@ const AdminSpaceCommunityPage = ({ routePrefix = '../' }: SettingsPageProps) =>
communityGuidelines,
profileId,
loading,
removeCommunityGuidelinesContentLoading,
onSelectCommunityGuidelinesTemplate,
onUpdateCommunityGuidelines,
onDeleteAndSaveContent,
onDeleteCommunityGuidelinesContent: onDeleteCommunityGuidelines,
}) => {
const hasDeleteContentButton =
Boolean(communityGuidelines?.displayName) ||
Boolean(communityGuidelines?.description) ||
Number(communityGuidelines?.references.length) > 0;

return (
<>
<PageContentBlockCollapsible
Expand Down Expand Up @@ -201,10 +195,8 @@ const AdminSpaceCommunityPage = ({ routePrefix = '../' }: SettingsPageProps) =>
data={communityGuidelines}
loading={loading}
profileId={profileId}
removeCommunityGuidelinesContentLoading={removeCommunityGuidelinesContentLoading}
onSubmit={onUpdateCommunityGuidelines}
hasDeleteContentButton={hasDeleteContentButton}
onDeleteAndSaveContent={onDeleteAndSaveContent}
onDeleteCommunityGuidelines={onDeleteCommunityGuidelines}
/>
</PageContentBlockCollapsible>

Expand Down
72 changes: 38 additions & 34 deletions src/domain/journey/subspace/pages/AdminSubspaceCommunityPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,41 +132,45 @@ const AdminSubspaceCommunityPage: FC<SettingsPageProps> = ({ routePrefix = '../'
loading,
onSelectCommunityGuidelinesTemplate,
onUpdateCommunityGuidelines,
}) => (
<>
<PageContentBlockCollapsible
header={<BlockTitle>{t('community.communityGuidelines.title')}</BlockTitle>}
primaryAction={
<Button
variant="outlined"
onClick={() => setCommunityGuidelinesTemplatesDialogOpen(true)}
startIcon={<InnovationLibraryIcon />}
>
{t('common.library')}
</Button>
}
>
<CommunityGuidelinesForm
data={communityGuidelines}
loading={loading}
onSubmit={onUpdateCommunityGuidelines}
profileId={profileId}
onDeleteCommunityGuidelinesContent,
}) => {
return (
<>
<PageContentBlockCollapsible
header={<BlockTitle>{t('community.communityGuidelines.title')}</BlockTitle>}
primaryAction={
<Button
variant="outlined"
onClick={() => setCommunityGuidelinesTemplatesDialogOpen(true)}
startIcon={<InnovationLibraryIcon />}
>
{t('common.library')}
</Button>
}
>
<CommunityGuidelinesForm
data={communityGuidelines}
loading={loading}
onSubmit={onUpdateCommunityGuidelines}
profileId={profileId}
onDeleteCommunityGuidelines={onDeleteCommunityGuidelinesContent}
/>
</PageContentBlockCollapsible>
<ImportTemplatesDialog
open={communityGuidelinesTemplatesDialogOpen}
templateType={TemplateType.CommunityGuidelines}
onClose={() => setCommunityGuidelinesTemplatesDialogOpen(false)}
onSelectTemplate={onSelectCommunityGuidelinesTemplate}
enablePlatformTemplates
actionButton={
<LoadingButton startIcon={<SystemUpdateAltIcon />} variant="contained">
{t('buttons.use')}
</LoadingButton>
}
/>
</PageContentBlockCollapsible>
<ImportTemplatesDialog
open={communityGuidelinesTemplatesDialogOpen}
templateType={TemplateType.CommunityGuidelines}
onClose={() => setCommunityGuidelinesTemplatesDialogOpen(false)}
onSelectTemplate={onSelectCommunityGuidelinesTemplate}
enablePlatformTemplates
actionButton={
<LoadingButton startIcon={<SystemUpdateAltIcon />} variant="contained">
{t('buttons.use')}
</LoadingButton>
}
/>
</>
)}
</>
);
}}
</CommunityGuidelinesContainer>
<PageContentColumn columns={6}>
<PageContentBlock>
Expand Down

0 comments on commit f04b698

Please sign in to comment.