fix ( donasi )
deskripsi: - fix upload kabar berita donasi - fix upload edit berita donasi
This commit is contained in:
@@ -68,18 +68,3 @@ export async function GET(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main({ id }: { id: string }) {
|
|
||||||
const fixData = await prisma.beritaInvestasi.findMany({
|
|
||||||
take: 10,
|
|
||||||
skip: 0,
|
|
||||||
orderBy: {
|
|
||||||
updatedAt: "desc",
|
|
||||||
},
|
|
||||||
where: {
|
|
||||||
investasiId: id.trim(),
|
|
||||||
active: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
console.log("data sebelum disconnect>>", fixData);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import { Donasi_CreateKabar } from "@/app_modules/donasi";
|
import { Donasi_CreateKabar } from "@/app_modules/donasi";
|
||||||
|
|
||||||
export default async function Page({ params }: { params: { id: string } }) {
|
export default async function Page() {
|
||||||
const donasiId = params.id;
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Donasi_CreateKabar donasiId={donasiId} />
|
<Donasi_CreateKabar />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,4 @@ process.on("SIGINT", async () => {
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
// console.log("==> Test prisma");
|
|
||||||
|
|
||||||
export default prisma;
|
export default prisma;
|
||||||
|
|||||||
@@ -1,37 +1,37 @@
|
|||||||
|
import { DIRECTORY_ID } from "@/app/lib";
|
||||||
import { MainColor } from "@/app_modules/_global/color";
|
import { MainColor } from "@/app_modules/_global/color";
|
||||||
import {
|
import {
|
||||||
ComponentGlobal_BoxInformation,
|
ComponentGlobal_BoxInformation,
|
||||||
ComponentGlobal_BoxUploadImage,
|
ComponentGlobal_BoxUploadImage,
|
||||||
|
ComponentGlobal_ButtonUploadFileImage,
|
||||||
ComponentGlobal_InputCountDown,
|
ComponentGlobal_InputCountDown,
|
||||||
ComponentGlobal_LoadImageCustom,
|
ComponentGlobal_LoadImageCustom,
|
||||||
} from "@/app_modules/_global/component";
|
} from "@/app_modules/_global/component";
|
||||||
import {
|
import {
|
||||||
AspectRatio,
|
funGlobal_DeleteFileById,
|
||||||
Button,
|
funGlobal_UploadToStorage,
|
||||||
FileButton,
|
} from "@/app_modules/_global/fun";
|
||||||
Group,
|
|
||||||
Image,
|
|
||||||
Stack,
|
|
||||||
Text,
|
|
||||||
TextInput,
|
|
||||||
Textarea,
|
|
||||||
} from "@mantine/core";
|
|
||||||
import { IconCamera, IconUpload } from "@tabler/icons-react";
|
|
||||||
import _ from "lodash";
|
|
||||||
import { useRouter } from "next/navigation";
|
|
||||||
import { useState } from "react";
|
|
||||||
import { MODEL_DONASI_KABAR } from "../../model/interface";
|
|
||||||
import {
|
import {
|
||||||
ComponentGlobal_NotifikasiBerhasil,
|
ComponentGlobal_NotifikasiBerhasil,
|
||||||
ComponentGlobal_NotifikasiGagal,
|
ComponentGlobal_NotifikasiGagal,
|
||||||
ComponentGlobal_NotifikasiPeringatan,
|
ComponentGlobal_NotifikasiPeringatan,
|
||||||
} from "@/app_modules/_global/notif_global";
|
} from "@/app_modules/_global/notif_global";
|
||||||
import { DIRECTORY_ID } from "@/app/lib";
|
|
||||||
import {
|
import {
|
||||||
funGlobal_DeleteFileById,
|
AspectRatio,
|
||||||
funGlobal_UploadToStorage,
|
Button,
|
||||||
} from "@/app_modules/_global/fun";
|
Center,
|
||||||
|
Image,
|
||||||
|
Stack,
|
||||||
|
TextInput,
|
||||||
|
Textarea,
|
||||||
|
} from "@mantine/core";
|
||||||
|
import { IconPhoto } from "@tabler/icons-react";
|
||||||
|
import _ from "lodash";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useState } from "react";
|
||||||
import { donasi_funUpdateKabar } from "../../fun";
|
import { donasi_funUpdateKabar } from "../../fun";
|
||||||
|
import { MODEL_DONASI_KABAR } from "../../model/interface";
|
||||||
|
import { clientLogger } from "@/util/clientLogger";
|
||||||
|
|
||||||
export function Donasi_ViewEditKabar({
|
export function Donasi_ViewEditKabar({
|
||||||
dataKabar,
|
dataKabar,
|
||||||
@@ -59,9 +59,8 @@ export function Donasi_ViewEditKabar({
|
|||||||
|
|
||||||
if (!uploadImage.success) {
|
if (!uploadImage.success) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return ComponentGlobal_NotifikasiPeringatan(
|
ComponentGlobal_NotifikasiPeringatan("Gagal upload file gambar");
|
||||||
"Gagal upload file gambar"
|
return;
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await donasi_funUpdateKabar({
|
const res = await donasi_funUpdateKabar({
|
||||||
@@ -72,12 +71,15 @@ export function Donasi_ViewEditKabar({
|
|||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
||||||
const deleteImage = await funGlobal_DeleteFileById({
|
if (dataKabar.imageId !== null) {
|
||||||
fileId: data.imageId,
|
const deleteImage = await funGlobal_DeleteFileById({
|
||||||
});
|
fileId: data.imageId,
|
||||||
if (!deleteImage.success) {
|
});
|
||||||
setLoading(false);
|
|
||||||
ComponentGlobal_NotifikasiPeringatan("Gagal hapus gambar lama");
|
if (!deleteImage.success) {
|
||||||
|
setLoading(false);
|
||||||
|
clientLogger.error("Gagal hapus gambar lama");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||||
@@ -92,7 +94,6 @@ export function Donasi_ViewEditKabar({
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
setLoading(false);
|
|
||||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||||
router.back();
|
router.back();
|
||||||
} else {
|
} else {
|
||||||
@@ -101,7 +102,8 @@ export function Donasi_ViewEditKabar({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
setLoading(false);
|
||||||
|
clientLogger.error("Error update donasi", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +131,7 @@ export function Donasi_ViewEditKabar({
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Textarea
|
<Textarea
|
||||||
maxLength={500}
|
maxLength={1000}
|
||||||
styles={{
|
styles={{
|
||||||
label: {
|
label: {
|
||||||
color: "white",
|
color: "white",
|
||||||
@@ -139,7 +141,7 @@ export function Donasi_ViewEditKabar({
|
|||||||
withAsterisk
|
withAsterisk
|
||||||
placeholder="Masukan deskripsi kabar"
|
placeholder="Masukan deskripsi kabar"
|
||||||
autosize
|
autosize
|
||||||
maxRows={4}
|
maxRows={10}
|
||||||
minRows={2}
|
minRows={2}
|
||||||
value={data.deskripsi}
|
value={data.deskripsi}
|
||||||
onChange={(val) => {
|
onChange={(val) => {
|
||||||
@@ -151,7 +153,7 @@ export function Donasi_ViewEditKabar({
|
|||||||
/>
|
/>
|
||||||
<ComponentGlobal_InputCountDown
|
<ComponentGlobal_InputCountDown
|
||||||
lengthInput={data.deskripsi.length}
|
lengthInput={data.deskripsi.length}
|
||||||
maxInput={500}
|
maxInput={1000}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Stack spacing={5}>
|
<Stack spacing={5}>
|
||||||
@@ -167,10 +169,7 @@ export function Donasi_ViewEditKabar({
|
|||||||
</AspectRatio>
|
</AspectRatio>
|
||||||
) : data.imageId === null ? (
|
) : data.imageId === null ? (
|
||||||
<Stack justify="center" align="center" h={"100%"}>
|
<Stack justify="center" align="center" h={"100%"}>
|
||||||
<IconUpload color="white" />
|
<IconPhoto size={100} />
|
||||||
<Text fz={10} fs={"italic"} c={"white"} fw={"bold"}>
|
|
||||||
Upload Gambar
|
|
||||||
</Text>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
) : (
|
) : (
|
||||||
<Stack justify="center" align="center" h={"100%"} p={"sm"}>
|
<Stack justify="center" align="center" h={"100%"} p={"sm"}>
|
||||||
@@ -183,35 +182,12 @@ export function Donasi_ViewEditKabar({
|
|||||||
</ComponentGlobal_BoxUploadImage>
|
</ComponentGlobal_BoxUploadImage>
|
||||||
|
|
||||||
{/* Upload Foto */}
|
{/* Upload Foto */}
|
||||||
<Group position="center">
|
<Center>
|
||||||
<FileButton
|
<ComponentGlobal_ButtonUploadFileImage
|
||||||
onChange={async (files: any) => {
|
onSetFile={setFile}
|
||||||
try {
|
onSetImage={setImg}
|
||||||
const buffer = URL.createObjectURL(
|
/>
|
||||||
new Blob([new Uint8Array(await files.arrayBuffer())])
|
</Center>
|
||||||
);
|
|
||||||
setImg(buffer);
|
|
||||||
setFile(files);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
accept="image/png,image/jpeg"
|
|
||||||
>
|
|
||||||
{(props) => (
|
|
||||||
<Button
|
|
||||||
{...props}
|
|
||||||
leftIcon={<IconCamera color="black" />}
|
|
||||||
radius={50}
|
|
||||||
bg={MainColor.yellow}
|
|
||||||
color="yellow"
|
|
||||||
c={"black"}
|
|
||||||
>
|
|
||||||
Upload Gambar
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</FileButton>
|
|
||||||
</Group>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -1,33 +1,38 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { DIRECTORY_ID } from "@/app/lib";
|
||||||
import { MainColor } from "@/app_modules/_global/color/color_pallet";
|
import { MainColor } from "@/app_modules/_global/color/color_pallet";
|
||||||
import { ComponentGlobal_BoxUploadImage } from "@/app_modules/_global/component";
|
import {
|
||||||
|
ComponentGlobal_BoxUploadImage,
|
||||||
|
ComponentGlobal_ButtonUploadFileImage,
|
||||||
|
} from "@/app_modules/_global/component";
|
||||||
import ComponentGlobal_BoxInformation from "@/app_modules/_global/component/box_information";
|
import ComponentGlobal_BoxInformation from "@/app_modules/_global/component/box_information";
|
||||||
import ComponentGlobal_InputCountDown from "@/app_modules/_global/component/input_countdown";
|
import ComponentGlobal_InputCountDown from "@/app_modules/_global/component/input_countdown";
|
||||||
|
import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun";
|
||||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
||||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
|
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
|
||||||
import { notifikasiToUser_CreateKabarDonasi } from "@/app_modules/notifikasi/fun/create/create_notif_to_user_kabar_donasi";
|
import { notifikasiToUser_CreateKabarDonasi } from "@/app_modules/notifikasi/fun/create/create_notif_to_user_kabar_donasi";
|
||||||
|
import { clientLogger } from "@/util/clientLogger";
|
||||||
import {
|
import {
|
||||||
AspectRatio,
|
AspectRatio,
|
||||||
Button,
|
Button,
|
||||||
FileButton,
|
Center,
|
||||||
Group,
|
|
||||||
Image,
|
Image,
|
||||||
Stack,
|
Stack,
|
||||||
Text,
|
|
||||||
TextInput,
|
TextInput,
|
||||||
Textarea,
|
Textarea
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { IconCamera, IconUpload } from "@tabler/icons-react";
|
import { IconPhoto } from "@tabler/icons-react";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { useRouter } from "next/navigation";
|
import { useParams, useRouter } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Donasi_funCreateKabar } from "../../fun/create/fun_create_kabar";
|
import { Donasi_funCreateKabar } from "../../fun/create/fun_create_kabar";
|
||||||
import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun";
|
|
||||||
import { DIRECTORY_ID } from "@/app/lib";
|
|
||||||
|
|
||||||
export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
export default function Donasi_CreateKabar() {
|
||||||
|
const params = useParams<{ id: string }>();
|
||||||
|
const donasiId = params.id;
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [file, setFile] = useState<File | null>(null);
|
const [file, setFile] = useState<File | null>(null);
|
||||||
const [img, setImg] = useState<any | null>();
|
const [img, setImg] = useState<any | null>();
|
||||||
@@ -58,9 +63,8 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
|||||||
|
|
||||||
if (!uploadImage.success) {
|
if (!uploadImage.success) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return ComponentGlobal_NotifikasiPeringatan(
|
ComponentGlobal_NotifikasiPeringatan("Gagal upload file gambar");
|
||||||
"Gagal upload file gambar"
|
return;
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await Donasi_funCreateKabar({
|
const res = await Donasi_funCreateKabar({
|
||||||
@@ -76,7 +80,6 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
|||||||
|
|
||||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||||
router.back();
|
router.back();
|
||||||
setLoading(false);
|
|
||||||
} else {
|
} else {
|
||||||
ComponentGlobal_NotifikasiGagal(res.message);
|
ComponentGlobal_NotifikasiGagal(res.message);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -94,21 +97,21 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
|||||||
|
|
||||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||||
router.back();
|
router.back();
|
||||||
setLoading(false);
|
|
||||||
} else {
|
} else {
|
||||||
ComponentGlobal_NotifikasiGagal(res.message);
|
ComponentGlobal_NotifikasiGagal(res.message);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
setLoading(false);
|
||||||
|
clientLogger.error("Error upload berita", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack px={"lg"} pb={"lg"}>
|
<Stack px={"lg"} pb={"lg"}>
|
||||||
<ComponentGlobal_BoxInformation informasi="Gambar tidak wajib di isi ! Hanya upload jika di butuhkan." />
|
<ComponentGlobal_BoxInformation informasi="Upload gambar bersifat opsional untuk melengkapi kabar terkait donasi Anda." />
|
||||||
|
|
||||||
<TextInput
|
<TextInput
|
||||||
maxLength={100}
|
maxLength={100}
|
||||||
@@ -128,7 +131,7 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Textarea
|
<Textarea
|
||||||
maxLength={500}
|
maxLength={1000}
|
||||||
styles={{
|
styles={{
|
||||||
label: {
|
label: {
|
||||||
color: "white",
|
color: "white",
|
||||||
@@ -138,7 +141,7 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
|||||||
withAsterisk
|
withAsterisk
|
||||||
placeholder="Masukan deskripsi kabar"
|
placeholder="Masukan deskripsi kabar"
|
||||||
autosize
|
autosize
|
||||||
maxRows={4}
|
maxRows={10}
|
||||||
minRows={2}
|
minRows={2}
|
||||||
onChange={(val) => {
|
onChange={(val) => {
|
||||||
setKabar({
|
setKabar({
|
||||||
@@ -149,7 +152,7 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
|||||||
/>
|
/>
|
||||||
<ComponentGlobal_InputCountDown
|
<ComponentGlobal_InputCountDown
|
||||||
lengthInput={kabar.deskripsi.length}
|
lengthInput={kabar.deskripsi.length}
|
||||||
maxInput={500}
|
maxInput={1000}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Stack spacing={5}>
|
<Stack spacing={5}>
|
||||||
@@ -165,44 +168,18 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
|||||||
</AspectRatio>
|
</AspectRatio>
|
||||||
) : (
|
) : (
|
||||||
<Stack justify="center" align="center" h={"100%"}>
|
<Stack justify="center" align="center" h={"100%"}>
|
||||||
<IconUpload color="white" />
|
<IconPhoto size={100} />
|
||||||
<Text fz={10} fs={"italic"} c={"white"} fw={"bold"}>
|
|
||||||
Upload Gambar
|
|
||||||
</Text>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
)}
|
)}
|
||||||
</ComponentGlobal_BoxUploadImage>
|
</ComponentGlobal_BoxUploadImage>
|
||||||
|
|
||||||
{/* Upload Foto */}
|
{/* Upload Foto */}
|
||||||
<Group position="center">
|
<Center>
|
||||||
<FileButton
|
<ComponentGlobal_ButtonUploadFileImage
|
||||||
onChange={async (files: any) => {
|
onSetFile={setFile}
|
||||||
try {
|
onSetImage={setImg}
|
||||||
const buffer = URL.createObjectURL(
|
/>
|
||||||
new Blob([new Uint8Array(await files.arrayBuffer())])
|
</Center>
|
||||||
);
|
|
||||||
setImg(buffer);
|
|
||||||
setFile(files);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
accept="image/png,image/jpeg"
|
|
||||||
>
|
|
||||||
{(props) => (
|
|
||||||
<Button
|
|
||||||
{...props}
|
|
||||||
leftIcon={<IconCamera color="black" />}
|
|
||||||
radius={50}
|
|
||||||
bg={MainColor.yellow}
|
|
||||||
color="yellow"
|
|
||||||
c={"black"}
|
|
||||||
>
|
|
||||||
Upload Gambar
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</FileButton>
|
|
||||||
</Group>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ export async function notifikasiToUser_CreateKabarDonasi({
|
|||||||
const dataFix = Array.from(data);
|
const dataFix = Array.from(data);
|
||||||
|
|
||||||
for (let authorId of dataFix) {
|
for (let authorId of dataFix) {
|
||||||
console.log(authorId);
|
|
||||||
const createNotifikasi = await prisma.notifikasi.create({
|
const createNotifikasi = await prisma.notifikasi.create({
|
||||||
data: {
|
data: {
|
||||||
userRoleId: "1",
|
userRoleId: "1",
|
||||||
|
|||||||
Reference in New Issue
Block a user