Skip to content

Commit

Permalink
Merge pull request #21 from qridwan/6-bug-editdelete-note
Browse files Browse the repository at this point in the history
🐛 Fix: => Edit note from details page not reflecting after UPDATE/DELETE operation
  • Loading branch information
qridwan committed Jun 2, 2024
2 parents be97d6c + 07a95d1 commit d7b1f90
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
12 changes: 1 addition & 11 deletions src/components/Home/EditNote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ const EditNote = ({ note, close }: { note: noteType, close?: () => void }) => {
const [editnote, { isLoading }] = useEditnoteMutation();
const [tags, setTags] = useState<string[]>([]);
const [content, setContent] = useState<string>(note.content);

const handleChangeEditor = ({ editor }: any) => {
setContent(editor?.getHTML() as string);
};

const form = useForm({
initialValues: {
title: note.title,
Expand All @@ -42,29 +40,21 @@ const EditNote = ({ note, close }: { note: noteType, close?: () => void }) => {
id: note?.id,
},
});

return (
<div>
<Container my={0} sx={{ minHeight: 450, display: 'flex', alignItems: 'center' }} >


<Paper withBorder sx={{ width: '100%' }} shadow="md" p={10} mt={10} radius="md">
<form onSubmit={form.onSubmit(async (values): Promise<void> => {


const res: any = await editnote({
...values,
content: content,
notebook_id: values?.notebook_id ? Number(values?.notebook_id) : null,
category_id: values.category_id ? Number(values?.category_id) : null,
} as noteType);


const isSuccess = Boolean(res?.data?.status === 'Success');
const icon = isSuccess ? <IconCheck /> : <IconX color="red" />;
notify(isSuccess, "Note successfully updated!", icon);



if (isSuccess) {
form.reset();
close && close();
Expand Down
4 changes: 3 additions & 1 deletion src/pages/NoteDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { formatDate } from '../helpers/dates';
const NoteDetails = () => {
const { id: noteId } = useParams();
const [openedEdit, { close: closeEdit }] = useDisclosure(false);
const { data: note } = useSinglenoteQuery(noteId as string);
const { data: note } = useSinglenoteQuery(noteId as string, { refetchOnMountOrArgChange: true });
const navigate = useNavigate();

const { classes } = useStyles();
Expand All @@ -46,6 +46,8 @@ const NoteDetails = () => {
const [deletetrash, { isLoading }] = useDeletetrashMutation();




return (
<Container size={'md'}>
<Grid justify='center' align='start'>
Expand Down
2 changes: 1 addition & 1 deletion src/redux/api/apiSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ export const apiSlice = createApi({
}
return result;
},
tagTypes: ["reviews", "books", "notebook", "notes", "trash"],
tagTypes: ["reviews", "books", "notebook", "notes", "trash", "single_note"],
endpoints: () => ({}),
});
5 changes: 3 additions & 2 deletions src/redux/features/notes/noteApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const noteApi = api.injectEndpoints({
}),
singlenote: builder.query({
query: (id: string) => `/notes/${id}`,
providesTags: ["single_note"],
}),
featurednote: builder.query({
query: () => `/note/featured`,
Expand All @@ -39,7 +40,7 @@ const noteApi = api.injectEndpoints({
url: `/notes/${id}`,
method: "DELETE",
}),
invalidatesTags: ["notes", "trash"],
invalidatesTags: ["notes", "trash", "single_note"],
}),
addnote: builder.mutation({
query: (data: noteType) => ({
Expand All @@ -55,7 +56,7 @@ const noteApi = api.injectEndpoints({
method: "PATCH",
body: data,
}),
invalidatesTags: ["notes"],
invalidatesTags: ["notes", "single_note"],
}),
addReview: builder.mutation({
query: (data: {
Expand Down

0 comments on commit d7b1f90

Please sign in to comment.