Donasi Create
# feat: - Create Donasi ## No Issuee
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
AspectRatio,
|
||||
Button,
|
||||
Center,
|
||||
FileButton,
|
||||
Image,
|
||||
Paper,
|
||||
Stack,
|
||||
@@ -16,24 +17,65 @@ import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { gs_donasi_tabs_posting } from "../global_state";
|
||||
import BoxInformasiDonasi from "../component/box_informasi";
|
||||
import { MODEL_DONASI_TEMPORARY } from "../model/interface";
|
||||
import _ from "lodash";
|
||||
import toast from "react-simple-toasts";
|
||||
import { Donasi_funCreate } from "../fun/create/fun_create_donasi";
|
||||
|
||||
export default function CreateCeritaPenggalangDonasi() {
|
||||
export default function CreateCeritaPenggalangDonasi({
|
||||
dataTemporary,
|
||||
userId
|
||||
}: {
|
||||
dataTemporary: MODEL_DONASI_TEMPORARY;
|
||||
userId: string
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [tabsPostingDonasi, setTabsPostingDonasi] = useAtom(
|
||||
gs_donasi_tabs_posting
|
||||
);
|
||||
const [value, setValue] = useState({
|
||||
const [create, setCreate] = useState({
|
||||
pembukaan: "",
|
||||
cerita: "",
|
||||
});
|
||||
const [temporary, setTemporary] = useState(dataTemporary);
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [imageCerita, setImageCerita] = useState<any | null>();
|
||||
|
||||
async function onCreate() {
|
||||
router.push(RouterDonasi.page_pop_up_create)
|
||||
setTabsPostingDonasi("Review")
|
||||
if (_.values(create).includes("")) return toast("Lengkapi Data");
|
||||
if (!file) return toast("Lengkapi Gambar");
|
||||
|
||||
const gambar = new FormData();
|
||||
gambar.append("file", file as any);
|
||||
|
||||
const body = {
|
||||
id: temporary.id,
|
||||
title: temporary.title,
|
||||
target: temporary.target,
|
||||
imagesId: temporary.imagesId,
|
||||
donasiMaster_KategoriId: temporary.donasiMaster_KategoriId,
|
||||
donasiMaster_DurasiId: temporary.donasiMaster_DurasiId,
|
||||
authorId: userId,
|
||||
CeritaDonasi: {
|
||||
pembukaan: create.pembukaan,
|
||||
cerita: create.cerita,
|
||||
},
|
||||
};
|
||||
|
||||
await Donasi_funCreate(body as any, gambar).then((res) => {
|
||||
if (res.status === 201) {
|
||||
router.push(RouterDonasi.page_pop_up_create);
|
||||
setTabsPostingDonasi("Review");
|
||||
} else {
|
||||
toast(res.message)
|
||||
}
|
||||
});
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<Stack spacing={"md"} px={"md"}>
|
||||
<BoxInformasiDonasi informasi="Ceritakan dengan jujur & benar mengapa Penggalanagn Dana ini harus diadakan!"/>
|
||||
{/* <pre>{JSON.stringify(dataTempo, null, 2)}</pre> */}
|
||||
<BoxInformasiDonasi informasi="Ceritakan dengan jujur & benar mengapa Penggalanagn Dana ini harus diadakan!" />
|
||||
<Textarea
|
||||
autosize
|
||||
minRows={2}
|
||||
@@ -42,12 +84,53 @@ setTabsPostingDonasi("Review")
|
||||
label="Pembukaan"
|
||||
placeholder="Pembuka dari isi cerita"
|
||||
onChange={(val) =>
|
||||
setValue({
|
||||
...value,
|
||||
setCreate({
|
||||
...create,
|
||||
pembukaan: val.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<Stack spacing={"xs"}>
|
||||
<AspectRatio ratio={16 / 9}>
|
||||
<Paper radius={"md"}>
|
||||
<Image
|
||||
alt="Foto"
|
||||
src={imageCerita ? imageCerita : "/aset/no-img.png"}
|
||||
/>
|
||||
</Paper>
|
||||
</AspectRatio>
|
||||
|
||||
<Center>
|
||||
<FileButton
|
||||
onChange={async (files: any | null) => {
|
||||
try {
|
||||
const buffer = URL.createObjectURL(
|
||||
new Blob([new Uint8Array(await files.arrayBuffer())])
|
||||
);
|
||||
// console.log(buffer, "ini buffer");
|
||||
// console.log(files, " ini file");
|
||||
setImageCerita(buffer);
|
||||
setFile(files);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}}
|
||||
accept="image/png,image/jpeg"
|
||||
>
|
||||
{(props) => (
|
||||
<Button
|
||||
{...props}
|
||||
radius={"xl"}
|
||||
variant="outline"
|
||||
w={150}
|
||||
leftIcon={<IconCamera />}
|
||||
>
|
||||
Upload
|
||||
</Button>
|
||||
)}
|
||||
</FileButton>
|
||||
</Center>
|
||||
</Stack>
|
||||
<Textarea
|
||||
autosize
|
||||
minRows={2}
|
||||
@@ -56,30 +139,13 @@ setTabsPostingDonasi("Review")
|
||||
label="Cerita"
|
||||
placeholder="Ceritakan alasan mengapa harus membuat Penggalangan Dana"
|
||||
onChange={(val) =>
|
||||
setValue({
|
||||
...value,
|
||||
setCreate({
|
||||
...create,
|
||||
cerita: val.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
|
||||
<Stack spacing={"xs"}>
|
||||
<Center>
|
||||
<Button
|
||||
radius={"xl"}
|
||||
variant="outline"
|
||||
w={150}
|
||||
leftIcon={<IconCamera />}
|
||||
>
|
||||
Upload
|
||||
</Button>
|
||||
</Center>
|
||||
<AspectRatio ratio={16 / 9}>
|
||||
<Paper radius={"md"}>
|
||||
<Image alt="Foto" src={"/aset/no-img.png"} />
|
||||
</Paper>
|
||||
</AspectRatio>
|
||||
</Stack>
|
||||
<Button w={"100%"} radius={"xl"} onClick={() => onCreate()}>
|
||||
Simpan
|
||||
</Button>
|
||||
|
||||
160
src/app_modules/donasi/create/create_donasi.tsx
Normal file
160
src/app_modules/donasi/create/create_donasi.tsx
Normal file
@@ -0,0 +1,160 @@
|
||||
"use client";
|
||||
|
||||
import { RouterDonasi } from "@/app/lib/router_hipmi/router_donasi";
|
||||
import {
|
||||
ActionIcon,
|
||||
AspectRatio,
|
||||
Box,
|
||||
Button,
|
||||
Center,
|
||||
FileButton,
|
||||
Image,
|
||||
Paper,
|
||||
Select,
|
||||
Stack,
|
||||
Text,
|
||||
TextInput,
|
||||
Textarea,
|
||||
} from "@mantine/core";
|
||||
import { IconCamera } from "@tabler/icons-react";
|
||||
import { useAtom } from "jotai";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import BoxInformasiDonasi from "../component/box_informasi";
|
||||
import { MODEL_DONASI_ALL_MASTER } from "../model/interface";
|
||||
import { useState } from "react";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import Donasi_funCreateTemporary from "../fun/create/fun_create_donasi_temporary";
|
||||
import toast from "react-simple-toasts";
|
||||
import _ from "lodash";
|
||||
|
||||
export default function CreateDonasi({
|
||||
masterKategori,
|
||||
masterDurasi,
|
||||
}: {
|
||||
masterKategori: MODEL_DONASI_ALL_MASTER[];
|
||||
masterDurasi: MODEL_DONASI_ALL_MASTER[];
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [kategori, setKategori] = useState(masterKategori);
|
||||
const [durasi, setDurasi] = useState(masterDurasi);
|
||||
const [create, setCreate] = useState({
|
||||
kategoriId: "",
|
||||
title: "",
|
||||
target: "",
|
||||
durasiId: "",
|
||||
});
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [imageDonasi, setImageDonasi] = useState<any | null>();
|
||||
|
||||
async function onCreate() {
|
||||
if (_.values(create).includes("")) return toast("Lengkapi Data");
|
||||
if (!file) return toast("Lengkapi Gambar");
|
||||
|
||||
const gambar = new FormData();
|
||||
gambar.append("file", file as any);
|
||||
|
||||
await Donasi_funCreateTemporary(create as any, gambar).then((res) => {
|
||||
if (res.status === 201) {
|
||||
router.push(RouterDonasi.create_cerita_penggalang + `${res.donasiId}`);
|
||||
} else {
|
||||
toast(res.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack spacing={"md"} px={"md"}>
|
||||
<BoxInformasiDonasi informasi="Lengkapi semua data di bawah untuk selanjutnya mengisi cerita Penggalangan Dana!" />
|
||||
<Select
|
||||
label="Kategori"
|
||||
placeholder="Pilih kategori penggalangan dana"
|
||||
withAsterisk
|
||||
data={kategori.map((e) => ({
|
||||
value: e.id,
|
||||
label: e.name,
|
||||
}))}
|
||||
onChange={(val: string) =>
|
||||
setCreate({
|
||||
...create,
|
||||
kategoriId: val,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<Stack>
|
||||
<AspectRatio ratio={16 / 9}>
|
||||
<Paper radius={"md"}>
|
||||
<Image
|
||||
alt="Foto"
|
||||
src={imageDonasi ? imageDonasi : "/aset/no-img.png"}
|
||||
/>
|
||||
</Paper>
|
||||
</AspectRatio>
|
||||
<Center>
|
||||
<FileButton
|
||||
onChange={async (files: any | null) => {
|
||||
try {
|
||||
const buffer = URL.createObjectURL(
|
||||
new Blob([new Uint8Array(await files.arrayBuffer())])
|
||||
);
|
||||
// console.log(buffer, "ini buffer");
|
||||
// console.log(files, " ini file");
|
||||
setImageDonasi(buffer);
|
||||
setFile(files);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}}
|
||||
accept="image/png,image/jpeg"
|
||||
>
|
||||
{(props) => (
|
||||
<Button
|
||||
{...props}
|
||||
radius={"xl"}
|
||||
variant="outline"
|
||||
w={150}
|
||||
leftIcon={<IconCamera />}
|
||||
>
|
||||
Upload
|
||||
</Button>
|
||||
)}
|
||||
</FileButton>
|
||||
</Center>
|
||||
</Stack>
|
||||
<Stack>
|
||||
<TextInput
|
||||
withAsterisk
|
||||
label="Judul Donasi"
|
||||
placeholder="Contoh: Renovasi Masjid pada kampung, dll"
|
||||
onChange={(val) =>
|
||||
setCreate({ ...create, title: val.target.value })
|
||||
}
|
||||
/>
|
||||
<TextInput
|
||||
type="number"
|
||||
withAsterisk
|
||||
label="Target Dana"
|
||||
placeholder="Masukan nominal angka"
|
||||
onChange={(val) =>
|
||||
setCreate({ ...create, target: val.target.value })
|
||||
}
|
||||
/>
|
||||
<Select
|
||||
label="Durasi"
|
||||
placeholder="Jangka waktu penggalangan dana"
|
||||
withAsterisk
|
||||
data={durasi.map((e) => ({
|
||||
value: e.id,
|
||||
label: e.name + " " + `bulan`,
|
||||
}))}
|
||||
onChange={(val: string) => setCreate({ ...create, durasiId: val })}
|
||||
/>
|
||||
</Stack>
|
||||
<Button my={"lg"} radius={"xl"} onClick={() => onCreate()}>
|
||||
Selanjutnya
|
||||
</Button>
|
||||
</Stack>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { RouterDonasi } from "@/app/lib/router_hipmi/router_donasi";
|
||||
import {
|
||||
ActionIcon,
|
||||
AspectRatio,
|
||||
Box,
|
||||
Button,
|
||||
Center,
|
||||
Image,
|
||||
Paper,
|
||||
Select,
|
||||
Stack,
|
||||
Text,
|
||||
TextInput,
|
||||
Textarea,
|
||||
} from "@mantine/core";
|
||||
import { IconCamera } from "@tabler/icons-react";
|
||||
import { useAtom } from "jotai";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { gs_donasi_tabs_posting } from "../global_state";
|
||||
import toast from "react-simple-toasts";
|
||||
import BoxInformasiDonasi from "../component/box_informasi";
|
||||
|
||||
export default function CreateDonasi() {
|
||||
const router = useRouter();
|
||||
const [tabsPostingDonasi, setTabsPostingDonasi] = useAtom(
|
||||
gs_donasi_tabs_posting
|
||||
);
|
||||
|
||||
async function onCreate() {
|
||||
router.push(RouterDonasi.create_cerita_penggalang);
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<Stack spacing={"md"} px={"md"}>
|
||||
<BoxInformasiDonasi informasi="Lengkapi semua data di bawah untuk selanjutnya mengisi cerita Penggalangan Dana!" />
|
||||
<Select
|
||||
label="Kategori"
|
||||
placeholder="Pilih kategori penggalangan dana"
|
||||
withAsterisk
|
||||
data={[
|
||||
{ value: "1", label: "Medis" },
|
||||
{ value: "2", label: "Lingkungan" },
|
||||
{ value: "3", label: "Kegiatan Sosial" },
|
||||
{ value: "4", label: "Rumah Ibadah" },
|
||||
{ value: "5", label: "Bantuan Pendidikan" },
|
||||
]}
|
||||
/>
|
||||
<Stack>
|
||||
<AspectRatio ratio={16 / 9}>
|
||||
<Paper radius={"md"}>
|
||||
<Image alt="Foto" src={"/aset/no-img.png"} />
|
||||
</Paper>
|
||||
</AspectRatio>
|
||||
<Center>
|
||||
<Button
|
||||
radius={"xl"}
|
||||
variant="outline"
|
||||
w={150}
|
||||
leftIcon={<IconCamera />}
|
||||
>
|
||||
Upload
|
||||
</Button>
|
||||
</Center>
|
||||
</Stack>
|
||||
<Stack>
|
||||
<TextInput
|
||||
withAsterisk
|
||||
label="Judul Donasi"
|
||||
placeholder="Contoh: Renovasi Masjid pada kampung, dll"
|
||||
/>
|
||||
<TextInput type="number" withAsterisk label="Target Dana" placeholder="Masukan nominal angka" />
|
||||
<Select
|
||||
label="Durasi"
|
||||
placeholder="Jangka waktu penggalangan dana"
|
||||
withAsterisk
|
||||
data={[
|
||||
{ value: "30", label: "30 Hari" },
|
||||
{ value: "60", label: "60 Hari" },
|
||||
{ value: "90", label: "90 Hari" },
|
||||
]}
|
||||
/>
|
||||
</Stack>
|
||||
<Button my={"lg"} radius={"xl"} onClick={() => onCreate()}>
|
||||
Selanjutnya
|
||||
</Button>
|
||||
</Stack>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user