Skip to content

Commit

Permalink
remove community guidelines content
Browse files Browse the repository at this point in the history
Signed-off-by: reactoholic <petar.georgiev.kolev@gmail.com>
  • Loading branch information
reactoholic committed Dec 3, 2024
1 parent 36e7697 commit 3ed7767
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 78 deletions.
2 changes: 2 additions & 0 deletions src/core/apollo/generated/apollo-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2038,6 +2038,7 @@ export type MutationKeySpecifier = (
| 'messageUser'
| 'moveContributionToCallout'
| 'refreshVirtualContributorBodyOfKnowledge'
| 'removeCommunityGuidelinesContent'
| 'removeMessageOnRoom'
| 'removeOrganizationRoleFromUser'
| 'removePlatformRoleFromUser'
Expand Down Expand Up @@ -2201,6 +2202,7 @@ export type MutationFieldPolicy = {
messageUser?: FieldPolicy<any> | FieldReadFunction<any>;
moveContributionToCallout?: FieldPolicy<any> | FieldReadFunction<any>;
refreshVirtualContributorBodyOfKnowledge?: FieldPolicy<any> | FieldReadFunction<any>;
removeCommunityGuidelinesContent?: FieldPolicy<any> | FieldReadFunction<any>;
removeMessageOnRoom?: FieldPolicy<any> | FieldReadFunction<any>;
removeOrganizationRoleFromUser?: FieldPolicy<any> | FieldReadFunction<any>;
removePlatformRoleFromUser?: FieldPolicy<any> | FieldReadFunction<any>;
Expand Down
52 changes: 52 additions & 0 deletions src/core/apollo/generated/apollo-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10081,6 +10081,58 @@ export type UpdateCommunityGuidelinesMutationOptions = Apollo.BaseMutationOption
SchemaTypes.UpdateCommunityGuidelinesMutation,
SchemaTypes.UpdateCommunityGuidelinesMutationVariables
>;
export const RemoveCommunityGuidelinesContentDocument = gql`
mutation RemoveCommunityGuidelinesContent($communityGuidelinesData: RemoveCommunityGuidelinesContentInput!) {
removeCommunityGuidelinesContent(communityGuidelinesData: $communityGuidelinesData) {
...CommunityGuidelinesDetails
}
}
${CommunityGuidelinesDetailsFragmentDoc}
`;
export type RemoveCommunityGuidelinesContentMutationFn = Apollo.MutationFunction<
SchemaTypes.RemoveCommunityGuidelinesContentMutation,
SchemaTypes.RemoveCommunityGuidelinesContentMutationVariables
>;

/**
* __useRemoveCommunityGuidelinesContentMutation__
*
* To run a mutation, you first call `useRemoveCommunityGuidelinesContentMutation` within a React component and pass it any options that fit your needs.
* When your component renders, `useRemoveCommunityGuidelinesContentMutation` returns a tuple that includes:
* - A mutate function that you can call at any time to execute the mutation
* - An object with fields that represent the current status of the mutation's execution
*
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
*
* @example
* const [removeCommunityGuidelinesContentMutation, { data, loading, error }] = useRemoveCommunityGuidelinesContentMutation({
* variables: {
* communityGuidelinesData: // value for 'communityGuidelinesData'
* },
* });
*/
export function useRemoveCommunityGuidelinesContentMutation(
baseOptions?: Apollo.MutationHookOptions<
SchemaTypes.RemoveCommunityGuidelinesContentMutation,
SchemaTypes.RemoveCommunityGuidelinesContentMutationVariables
>
) {
const options = { ...defaultOptions, ...baseOptions };
return Apollo.useMutation<
SchemaTypes.RemoveCommunityGuidelinesContentMutation,
SchemaTypes.RemoveCommunityGuidelinesContentMutationVariables
>(RemoveCommunityGuidelinesContentDocument, options);
}

export type RemoveCommunityGuidelinesContentMutationHookResult = ReturnType<
typeof useRemoveCommunityGuidelinesContentMutation
>;
export type RemoveCommunityGuidelinesContentMutationResult =
Apollo.MutationResult<SchemaTypes.RemoveCommunityGuidelinesContentMutation>;
export type RemoveCommunityGuidelinesContentMutationOptions = Apollo.BaseMutationOptions<
SchemaTypes.RemoveCommunityGuidelinesContentMutation,
SchemaTypes.RemoveCommunityGuidelinesContentMutationVariables
>;
export const CreateGroupOnCommunityDocument = gql`
mutation createGroupOnCommunity($input: CreateUserGroupInput!) {
createGroupOnCommunity(groupData: $input) {
Expand Down
35 changes: 35 additions & 0 deletions src/core/apollo/generated/graphql-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3469,6 +3469,8 @@ export type Mutation = {
moveContributionToCallout: CalloutContribution;
/** Triggers a request to the backing AI Service to refresh the knowledge that is available to it. */
refreshVirtualContributorBodyOfKnowledge: Scalars['Boolean'];
/** Updates the CommunityGuidelines. */
removeCommunityGuidelinesContent: CommunityGuidelines;
/** Removes a message. */
removeMessageOnRoom: Scalars['MessageID'];
/** Removes Organization Role from user. */
Expand Down Expand Up @@ -3943,6 +3945,10 @@ export type MutationRefreshVirtualContributorBodyOfKnowledgeArgs = {
refreshData: RefreshVirtualContributorBodyOfKnowledgeInput;
};

export type MutationRemoveCommunityGuidelinesContentArgs = {
communityGuidelinesData: RemoveCommunityGuidelinesContentInput;
};

export type MutationRemoveMessageOnRoomArgs = {
messageData: RoomRemoveMessageInput;
};
Expand Down Expand Up @@ -5039,6 +5045,11 @@ export type RelayPaginatedSpacePageInfo = {
startCursor?: Maybe<Scalars['String']>;
};

export type RemoveCommunityGuidelinesContentInput = {
/** ID of the CommunityGuidelines that will be emptied */
communityGuidelinesID: Scalars['UUID'];
};

export type RemoveOrganizationRoleFromUserInput = {
organizationID: Scalars['UUID'];
role: OrganizationRole;
Expand Down Expand Up @@ -15558,6 +15569,30 @@ export type UpdateCommunityGuidelinesMutation = {
};
};

export type RemoveCommunityGuidelinesContentMutationVariables = Exact<{
communityGuidelinesData: RemoveCommunityGuidelinesContentInput;
}>;

export type RemoveCommunityGuidelinesContentMutation = {
__typename?: 'Mutation';
removeCommunityGuidelinesContent: {
__typename?: 'CommunityGuidelines';
id: string;
profile: {
__typename?: 'Profile';
id: string;
displayName: string;
description?: string | undefined;
references?:
| Array<{ __typename?: 'Reference'; id: string; name: string; uri: string; description?: string | undefined }>
| undefined;
};
authorization?:
| { __typename?: 'Authorization'; id: string; myPrivileges?: Array<AuthorizationPrivilege> | undefined }
| undefined;
};
};

export type CommunityPageMembersFragment = {
__typename?: 'User';
id: string;
Expand Down
8 changes: 7 additions & 1 deletion src/core/i18n/en/translation.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@
"LICENSE_MANAGER": "License Manager",
"BETA_TESTER": "Beta Tester",
"VC_CAMPAIGN": "VC Early Access"
}
},
"removeContent": "Remove Community Guidelines Content and Save"
},
"community": {
"memberUsers": "Member Users ({{count}})",
Expand Down Expand Up @@ -622,6 +623,7 @@
},
"communityGuidelines": {
"title": "Community Guidelines",
"saveAndDeleteContentSuccessMessage": "Community guidelines content removed and saved successfully.",
"updatedSuccessfully": "Community guidelines updated successfully.",
"adminsOnly": "Since there are no Community Guidelines specified, this block is only visible for admins and leads.",
"communityGuidelinesRedirect": "Click here to update the Community Guidelines in the Space settings.",
Expand Down Expand Up @@ -690,6 +692,10 @@
"dialogTitle": "Are you sure you want to remove this member?",
"dialogContent": "By clicking CONFIRM, {{member}} will be removed from this Community and all the underlying Subspaces {{memberFirstName}} may be member of. {{memberFirstName}}’s contributions will remain in place."
}
},
"removeGuidelinesConfirmationDialog": {
"title": "Remove Community Guidelines Content",
"content": "Are you sure you want to remove the Community Guidelines? This action cannot be undone."
}
},
"callout": {
Expand Down
4 changes: 3 additions & 1 deletion src/core/ui/forms/MarkdownInput/FormikMarkdownField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ export const FormikMarkdownField = ({

const handleChange = useCallback(
(event: ChangeEvent<HTMLInputElement>) => {
helper.setValue(event.target.value);
const trimmedValue = event.target.value.trim();
const newValue = trimmedValue === '<br>' ? '' : event.target.value;
helper.setValue(newValue);
},
[helper]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ mutation UpdateCommunityGuidelines($communityGuidelinesData: UpdateCommunityGuid
...CommunityGuidelinesDetails
}
}

mutation RemoveCommunityGuidelinesContent($communityGuidelinesData: RemoveCommunityGuidelinesContentInput!) {
removeCommunityGuidelinesContent(communityGuidelinesData: $communityGuidelinesData) {
...CommunityGuidelinesDetails
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ const CommunityGuidelinesBlock = ({ communityId, journeyUrl }: CommunityGuidelin
const openDialog = () => setIsCommunityGuidelinesInfoDialogOpen(true);
const closeDialog = () => setIsCommunityGuidelinesInfoDialogOpen(false);

const comunityReferences = data?.lookup.community?.guidelines.profile.references;
const comunityDescription = data?.lookup.community?.guidelines.profile.description;

const { t } = useTranslation();
const hasGuidelines = !!data?.lookup.community?.guidelines.profile.description;

const hasGuidelines = Boolean(data?.lookup.community?.guidelines.profile.description);
const isReadMoreVisible = Number(comunityDescription?.length) > 0 || Number(comunityReferences?.length) > 0;
const showGuidelines =
hasGuidelines ||
data?.lookup.community?.guidelines.authorization?.myPrivileges?.includes(AuthorizationPrivilege.Create);
Expand All @@ -51,7 +56,7 @@ const CommunityGuidelinesBlock = ({ communityId, journeyUrl }: CommunityGuidelin
<>
<PageContentBlock>
<PageContentBlockHeader title={data?.lookup?.community?.guidelines?.profile.displayName} />
{hasGuidelines ? (
{isReadMoreVisible ? (
<>
<Box display="flex" flexDirection="column" gap={gutters()}>
{loading && <CommunityGuidelinesSkeleton />}
Expand All @@ -65,6 +70,7 @@ const CommunityGuidelinesBlock = ({ communityId, journeyUrl }: CommunityGuidelin
</OverflowGradient>
)}
</Box>

<SeeMore label="buttons.readMore" onClick={openDialog} />
</>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
useCommunityGuidelinesQuery,
useCreateReferenceOnProfileMutation,
useDeleteReferenceMutation,
useRemoveCommunityGuidelinesContentMutation,
useTemplateContentLazyQuery,
useUpdateCommunityGuidelinesMutation,
} from '@/core/apollo/generated/apollo-hooks';
Expand All @@ -28,8 +29,10 @@ 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;
}

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

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

const onUpdateCommunityGuidelines = async (values: CommunityGuidelines) => {
if (!communityGuidelinesId) {
return;
Expand Down Expand Up @@ -93,6 +99,23 @@ const CommunityGuidelinesContainer = ({ communityId, children }: CommunityGuidel
});
};

const onDeleteAndSaveContent = async () => {
if (!communityGuidelinesId) {
return;
}

await removeCommunityGuidelinesContent({
variables: {
communityGuidelinesData: {
communityGuidelinesID: communityGuidelinesId,
},
},
onCompleted: () => notify(t('community.communityGuidelines.saveAndDeleteContentSuccessMessage'), 'success'),
awaitRefetchQueries: true,
refetchQueries: [refetchCommunityGuidelinesQuery({ communityId })],
});
};

const [fetchCommunityGuidelinesTemplates] = useTemplateContentLazyQuery();
const [removeReference, { loading: removingReference }] = useDeleteReferenceMutation();
const [createReference, { loading: addingReference }] = useCreateReferenceOnProfileMutation();
Expand Down Expand Up @@ -165,9 +188,11 @@ const CommunityGuidelinesContainer = ({ communityId, children }: CommunityGuidel
communityGuidelines,
communityGuidelinesId,
profileId,
removeCommunityGuidelinesContentLoading,
loading: loading || submittingGuidelines || removingReference || addingReference,
onUpdateCommunityGuidelines,
onSelectCommunityGuidelinesTemplate,
onDeleteAndSaveContent,
})}
</>
);
Expand Down
Loading

0 comments on commit 3ed7767

Please sign in to comment.