Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(933): refetching in /orgpost after deleting a post #962

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions src/components/OrgPostCard/OrgPostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
DELETE_POST_MUTATION,
UPDATE_POST_MUTATION,
} from 'GraphQl/Mutations/mutations';
import { ORGANIZATION_POST_CONNECTION_LIST } from 'GraphQl/Queries/Queries';
import defaultImg from 'assets/images/blank.png';
import { useTranslation } from 'react-i18next';
import { errorHandler } from 'utils/errorHandler';
Expand Down Expand Up @@ -58,29 +59,27 @@ function orgPostCard(props: InterfaceOrgPostCardProps): JSX.Element {
keyPrefix: 'orgPostCard',
});

const [create] = useMutation(DELETE_POST_MUTATION);
const [deleteMutation] = useMutation(DELETE_POST_MUTATION);
const [updatePost] = useMutation(UPDATE_POST_MUTATION);

const deletePost = async (): Promise<void> => {
try {
const { data } = await create({
variables: {
id: props.id,
},
});

function deletePost(): void {
deleteMutation({
variables: {
id: props.id,
},
/* istanbul ignore next */
if (data) {
onCompleted() {
toast.success(t('postDeleted'));
setTimeout(() => {
window.location.reload();
}, 2000);
}
} catch (error: any) {
toggleShowDeleteModal();
},
refetchQueries: [ORGANIZATION_POST_CONNECTION_LIST],
awaitRefetchQueries: true,
/* istanbul ignore next */
errorHandler(t, error);
}
};
onError(error) {
errorHandler(t, error);
},
});
}

const handleInputEvent = (
e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
Expand Down