# Forum Created
## feat - CRUD Forum - CRD Koment - Tampilan forum profile ### No issue
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"use client"
|
||||
"use client";
|
||||
|
||||
import {
|
||||
ActionIcon,
|
||||
@@ -16,11 +16,14 @@ import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useRouter } from "next/navigation";
|
||||
import ComponentGlobal_V2_LoadingPage from "@/app_modules/component_global/loading_page_v2";
|
||||
|
||||
|
||||
import dynamic from "next/dynamic";
|
||||
import React, { useState } from "react";
|
||||
import { useAtom } from "jotai";
|
||||
import { gs_forum_loading_edit_posting } from "../../global_state";
|
||||
import { MODEL_FORUM_POSTING } from "../../model/interface";
|
||||
import { forum_funEditPostingById } from "../../fun/edit/fun_edit_posting_by_id";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/component_global/notif_global/notifikasi_berhasil";
|
||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/component_global/notif_global/notifikasi_gagal";
|
||||
const ReactQuill = dynamic(
|
||||
() => {
|
||||
return import("react-quill");
|
||||
@@ -28,8 +31,12 @@ const ReactQuill = dynamic(
|
||||
{ ssr: false }
|
||||
);
|
||||
|
||||
export default function Forum_EditPosting() {
|
||||
const [value, setValue] = useState("");
|
||||
export default function Forum_EditPosting({
|
||||
dataPosting,
|
||||
}: {
|
||||
dataPosting: MODEL_FORUM_POSTING;
|
||||
}) {
|
||||
const [value, setValue] = useState(dataPosting);
|
||||
const [reload, setReload] = useState(false);
|
||||
useShallowEffect(() => {
|
||||
if (window && window.document) setReload(true);
|
||||
@@ -50,8 +57,12 @@ export default function Forum_EditPosting() {
|
||||
theme="bubble"
|
||||
placeholder="Apa yang sedang hangat dibicarakan ?"
|
||||
style={{ height: 150 }}
|
||||
value={value.diskusi}
|
||||
onChange={(val) => {
|
||||
setValue(val);
|
||||
setValue({
|
||||
...value,
|
||||
diskusi: val,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</Paper>
|
||||
@@ -59,24 +70,46 @@ export default function Forum_EditPosting() {
|
||||
{/* <ActionIcon>
|
||||
<IconPhotoUp />
|
||||
</ActionIcon> */}
|
||||
<ButtonAction />
|
||||
<ButtonAction diskusi={value.diskusi as any} postingId={value.id} />
|
||||
</Group>
|
||||
</Stack>
|
||||
<div dangerouslySetInnerHTML={{ __html: value }} />
|
||||
{/* <div dangerouslySetInnerHTML={{ __html: value }} /> */}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ButtonAction() {
|
||||
function ButtonAction({
|
||||
postingId,
|
||||
diskusi,
|
||||
}: {
|
||||
postingId: string;
|
||||
diskusi: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [loadingEdit, setLoadingEdit] = useAtom(gs_forum_loading_edit_posting);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function onUpdate() {
|
||||
await forum_funEditPostingById(postingId, diskusi).then((res) => {
|
||||
if (res.status === 200) {
|
||||
setLoading(true);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
setTimeout(() => router.back(), 1000)
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button radius={"xl"} onClick={() => {
|
||||
router.back()
|
||||
|
||||
}}>
|
||||
<Button
|
||||
loaderPosition="center"
|
||||
loading={loading ? true : false}
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
onUpdate();
|
||||
}}
|
||||
>
|
||||
Update
|
||||
</Button>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user