upd: diskusi
Deskripsi: - mati validasi form tambah diskusi - mati validasi form edit diskusi - loading pada saat tambah diskusi - loading pada saat edit diskusi No Issues:
This commit is contained in:
@@ -13,6 +13,7 @@ import { funCreateDiscussion } from "../lib/api_discussion";
|
|||||||
|
|
||||||
export default function FormCreateDiscussion({ id }: { id: string }) {
|
export default function FormCreateDiscussion({ id }: { id: string }) {
|
||||||
const [isValModal, setValModal] = useState(false)
|
const [isValModal, setValModal] = useState(false)
|
||||||
|
const [loadingModal, setLoadingModal] = useState(false)
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [isImg, setImg] = useState("")
|
const [isImg, setImg] = useState("")
|
||||||
const param = useParams<{ id: string, detail: string }>()
|
const param = useParams<{ id: string, detail: string }>()
|
||||||
@@ -50,7 +51,7 @@ export default function FormCreateDiscussion({ id }: { id: string }) {
|
|||||||
|
|
||||||
async function createDiscussion(val: boolean) {
|
async function createDiscussion(val: boolean) {
|
||||||
try {
|
try {
|
||||||
if (val) {
|
setLoadingModal(true)
|
||||||
const response = await funCreateDiscussion({
|
const response = await funCreateDiscussion({
|
||||||
desc: isData.desc,
|
desc: isData.desc,
|
||||||
idDivision: id
|
idDivision: id
|
||||||
@@ -60,16 +61,15 @@ export default function FormCreateDiscussion({ id }: { id: string }) {
|
|||||||
setDataRealtime(response.notif)
|
setDataRealtime(response.notif)
|
||||||
toast.success(response.message)
|
toast.success(response.message)
|
||||||
router.push(`/division/${param.id}/discussion/`)
|
router.push(`/division/${param.id}/discussion/`)
|
||||||
setValModal(false)
|
|
||||||
} else {
|
} else {
|
||||||
toast.error(response.message)
|
toast.error(response.message)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
toast.error("Gagal menambahkan diskusi, coba lagi nanti");
|
toast.error("Gagal menambahkan diskusi, coba lagi nanti");
|
||||||
} finally {
|
} finally {
|
||||||
setValModal(false)
|
setValModal(false)
|
||||||
|
setLoadingModal(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,12 +94,12 @@ export default function FormCreateDiscussion({ id }: { id: string }) {
|
|||||||
}}
|
}}
|
||||||
value={isData.desc}
|
value={isData.desc}
|
||||||
onChange={(e) => setData({ ...isData, desc: e.target.value })}
|
onChange={(e) => setData({ ...isData, desc: e.target.value })}
|
||||||
onBlur={() => setTouched({ ...touched, desc: true })}
|
// onBlur={() => setTouched({ ...touched, desc: true })}
|
||||||
error={
|
// error={
|
||||||
touched.desc && (
|
// touched.desc && (
|
||||||
isData.desc == "" ? "Form Tidak Boleh Kosong" : null
|
// isData.desc == "" ? "Form Tidak Boleh Kosong" : null
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
@@ -130,9 +130,11 @@ export default function FormCreateDiscussion({ id }: { id: string }) {
|
|||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<LayoutModal opened={isValModal} onClose={() => setValModal(false)}
|
<LayoutModal loading={loadingModal} opened={isValModal} onClose={() => setValModal(false)}
|
||||||
description="Apakah Anda yakin ingin menambah data?"
|
description="Apakah Anda yakin ingin menambah data?"
|
||||||
onYes={(val) => { createDiscussion(val) }} />
|
onYes={(val) => {
|
||||||
|
createDiscussion(val)
|
||||||
|
}} />
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,7 @@ import { useHookstate } from "@hookstate/core"
|
|||||||
|
|
||||||
export default function FormEditDiscussion() {
|
export default function FormEditDiscussion() {
|
||||||
const [isValModal, setValModal] = useState(false)
|
const [isValModal, setValModal] = useState(false)
|
||||||
|
const [loadingModal, setLoadingModal] = useState(false)
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const param = useParams<{ id: string, detail: string }>()
|
const param = useParams<{ id: string, detail: string }>()
|
||||||
const [isDataOne, setDataOne] = useState("")
|
const [isDataOne, setDataOne] = useState("")
|
||||||
@@ -35,9 +36,9 @@ export default function FormEditDiscussion() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchEditDiscussion(val: boolean) {
|
async function fetchEditDiscussion() {
|
||||||
try {
|
try {
|
||||||
if (val) {
|
setLoadingModal(true)
|
||||||
const response = await funEditDiscussion(param.detail, {
|
const response = await funEditDiscussion(param.detail, {
|
||||||
desc: isDataOne
|
desc: isDataOne
|
||||||
})
|
})
|
||||||
@@ -48,14 +49,14 @@ export default function FormEditDiscussion() {
|
|||||||
} else {
|
} else {
|
||||||
toast.error(response.message)
|
toast.error(response.message)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
setValModal(false)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
setValModal(false)
|
setValModal(false)
|
||||||
toast.error("Gagal menambahkan diskusi, coba lagi nanti");
|
toast.error("Gagal menambahkan diskusi, coba lagi nanti");
|
||||||
} finally {
|
} finally {
|
||||||
setValModal(false)
|
setValModal(false)
|
||||||
|
setLoadingModal(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,12 +113,12 @@ export default function FormEditDiscussion() {
|
|||||||
}}
|
}}
|
||||||
value={isDataOne}
|
value={isDataOne}
|
||||||
onChange={(e) => setDataOne(e.target.value)}
|
onChange={(e) => setDataOne(e.target.value)}
|
||||||
onBlur={() => setTouched({ ...touched, desc: true })}
|
// onBlur={() => setTouched({ ...touched, desc: true })}
|
||||||
error={
|
// error={
|
||||||
touched.desc && (
|
// touched.desc && (
|
||||||
isDataOne == "" ? "Form Tidak Boleh Kosong" : null
|
// isDataOne == "" ? "Form Tidak Boleh Kosong" : null
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
}
|
}
|
||||||
@@ -153,9 +154,15 @@ export default function FormEditDiscussion() {
|
|||||||
}
|
}
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<LayoutModal opened={isValModal} onClose={() => setValModal(false)}
|
<LayoutModal loading={loadingModal} opened={isValModal} onClose={() => setValModal(false)}
|
||||||
description="Apakah Anda yakin ingin mengubah data?"
|
description="Apakah Anda yakin ingin mengubah data?"
|
||||||
onYes={(val) => { fetchEditDiscussion(val) }} />
|
onYes={(val) => {
|
||||||
|
if (val) {
|
||||||
|
fetchEditDiscussion()
|
||||||
|
} else {
|
||||||
|
setValModal(false)
|
||||||
|
}
|
||||||
|
}} />
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user