fix: remirror image not updating (#294)

This commit is contained in:
Aaryan Khandelwal 2023-02-17 16:57:31 +05:30 committed by GitHub
parent 1665863bd9
commit 4b068398bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 37 deletions

View File

@ -35,10 +35,7 @@ export const BulkDeleteIssuesModal: React.FC<Props> = ({ isOpen, setIsOpen }) =>
const [query, setQuery] = useState(""); const [query, setQuery] = useState("");
const router = useRouter(); const router = useRouter();
const { workspaceSlug, projectId } = router.query;
const {
query: { workspaceSlug, projectId },
} = router;
const { data: issues } = useSWR( const { data: issues } = useSWR(
workspaceSlug && projectId workspaceSlug && projectId

View File

@ -49,7 +49,7 @@ const defaultValues: Partial<IIssue> = {
}; };
export interface IssueFormProps { export interface IssueFormProps {
handleFormSubmit: (values: Partial<IIssue>) => void; handleFormSubmit: (values: Partial<IIssue>) => Promise<void>;
initialData?: Partial<IIssue>; initialData?: Partial<IIssue>;
issues: IIssue[]; issues: IIssue[];
projectId: string; projectId: string;
@ -107,17 +107,18 @@ export const IssueForm: FC<IssueFormProps> = ({
reset({ reset({
...defaultValues, ...defaultValues,
project: projectId, project: projectId,
description: "",
description_html: "<p></p>",
}); });
}; };
useEffect(() => { useEffect(() => {
reset({ reset({
...defaultValues, ...defaultValues,
...watch(),
project: projectId,
...initialData, ...initialData,
project: projectId,
}); });
}, [initialData, reset, watch, projectId]); }, [initialData, reset, projectId]);
return ( return (
<> <>
@ -238,13 +239,11 @@ export const IssueForm: FC<IssueFormProps> = ({
<Controller <Controller
name="description" name="description"
control={control} control={control}
render={({ field: { value, onChange } }) => ( render={({ field: { value } }) => (
<RemirrorRichTextEditor <RemirrorRichTextEditor
value={value} value={value}
onBlur={(jsonValue, htmlValue) => { onJSONChange={(jsonValue) => setValue("description", jsonValue)}
setValue("description", jsonValue); onHTMLChange={(htmlValue) => setValue("description_html", htmlValue)}
setValue("description_html", htmlValue);
}}
placeholder="Enter Your Text..." placeholder="Enter Your Text..."
/> />
)} )}

View File

@ -141,30 +141,20 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = ({
if (!createMore) handleClose(); if (!createMore) handleClose();
setToastAlert({ setToastAlert({
title: "Success",
type: "success", type: "success",
message: "Issue created successfully", title: "Success!",
message: "Issue created successfully.",
}); });
if (payload.assignees_list?.some((assignee) => assignee === user?.id)) mutate(USER_ISSUE); if (payload.assignees_list?.some((assignee) => assignee === user?.id)) mutate(USER_ISSUE);
if (payload.parent && payload.parent !== "") mutate(SUB_ISSUES(payload.parent)); if (payload.parent && payload.parent !== "") mutate(SUB_ISSUES(payload.parent));
}) })
.catch((err) => { .catch(() => {
if (err.detail) { setToastAlert({
setToastAlert({ type: "error",
title: "Join the project.", title: "Error!",
type: "error", message: "Issue could not be created. Please try again.",
message: "Click select to join from projects page to start making changes",
});
}
Object.keys(err).map((key) => {
const message = err[key];
if (!message) return;
setError(key as keyof IIssue, {
message: Array.isArray(message) ? message.join(", ") : message,
});
}); });
}); });
}; };
@ -194,14 +184,16 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = ({
if (!createMore) handleClose(); if (!createMore) handleClose();
setToastAlert({ setToastAlert({
title: "Success",
type: "success", type: "success",
message: "Issue updated successfully", title: "Success!",
message: "Issue updated successfully.",
}); });
}) })
.catch((err) => { .catch(() => {
Object.keys(err).map((key) => { setToastAlert({
setError(key as keyof IIssue, { message: err[key].join(", ") }); type: "error",
title: "Error!",
message: "Issue could not be updated. Please try again.",
}); });
}); });
}; };
@ -211,8 +203,8 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = ({
const payload: Partial<IIssue> = { const payload: Partial<IIssue> = {
...formData, ...formData,
description: formData.description ? formData.description : "", description: formData.description ?? "",
description_html: formData.description_html ? formData.description_html : "<p></p>", description_html: formData.description_html ?? "<p></p>",
}; };
if (!data) await createIssue(payload); if (!data) await createIssue(payload);