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";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
const donasiId = params.id;
|
||||
export default async function Page() {
|
||||
return (
|
||||
<>
|
||||
<Donasi_CreateKabar donasiId={donasiId} />
|
||||
<Donasi_CreateKabar />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,4 @@ process.on("SIGINT", async () => {
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
// console.log("==> Test prisma");
|
||||
|
||||
export default prisma;
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
import { DIRECTORY_ID } from "@/app/lib";
|
||||
import { MainColor } from "@/app_modules/_global/color";
|
||||
import {
|
||||
ComponentGlobal_BoxInformation,
|
||||
ComponentGlobal_BoxUploadImage,
|
||||
ComponentGlobal_ButtonUploadFileImage,
|
||||
ComponentGlobal_InputCountDown,
|
||||
ComponentGlobal_LoadImageCustom,
|
||||
} from "@/app_modules/_global/component";
|
||||
import {
|
||||
AspectRatio,
|
||||
Button,
|
||||
FileButton,
|
||||
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";
|
||||
funGlobal_DeleteFileById,
|
||||
funGlobal_UploadToStorage,
|
||||
} from "@/app_modules/_global/fun";
|
||||
import {
|
||||
ComponentGlobal_NotifikasiBerhasil,
|
||||
ComponentGlobal_NotifikasiGagal,
|
||||
ComponentGlobal_NotifikasiPeringatan,
|
||||
} from "@/app_modules/_global/notif_global";
|
||||
import { DIRECTORY_ID } from "@/app/lib";
|
||||
import {
|
||||
funGlobal_DeleteFileById,
|
||||
funGlobal_UploadToStorage,
|
||||
} from "@/app_modules/_global/fun";
|
||||
AspectRatio,
|
||||
Button,
|
||||
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 { MODEL_DONASI_KABAR } from "../../model/interface";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
export function Donasi_ViewEditKabar({
|
||||
dataKabar,
|
||||
@@ -59,9 +59,8 @@ export function Donasi_ViewEditKabar({
|
||||
|
||||
if (!uploadImage.success) {
|
||||
setLoading(false);
|
||||
return ComponentGlobal_NotifikasiPeringatan(
|
||||
"Gagal upload file gambar"
|
||||
);
|
||||
ComponentGlobal_NotifikasiPeringatan("Gagal upload file gambar");
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await donasi_funUpdateKabar({
|
||||
@@ -72,12 +71,15 @@ export function Donasi_ViewEditKabar({
|
||||
if (res.status === 200) {
|
||||
setLoading(false);
|
||||
|
||||
const deleteImage = await funGlobal_DeleteFileById({
|
||||
fileId: data.imageId,
|
||||
});
|
||||
if (!deleteImage.success) {
|
||||
setLoading(false);
|
||||
ComponentGlobal_NotifikasiPeringatan("Gagal hapus gambar lama");
|
||||
if (dataKabar.imageId !== null) {
|
||||
const deleteImage = await funGlobal_DeleteFileById({
|
||||
fileId: data.imageId,
|
||||
});
|
||||
|
||||
if (!deleteImage.success) {
|
||||
setLoading(false);
|
||||
clientLogger.error("Gagal hapus gambar lama");
|
||||
}
|
||||
}
|
||||
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
@@ -92,7 +94,6 @@ export function Donasi_ViewEditKabar({
|
||||
});
|
||||
|
||||
if (res.status === 200) {
|
||||
setLoading(false);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.back();
|
||||
} else {
|
||||
@@ -101,7 +102,8 @@ export function Donasi_ViewEditKabar({
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
setLoading(false);
|
||||
clientLogger.error("Error update donasi", error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +131,7 @@ export function Donasi_ViewEditKabar({
|
||||
}}
|
||||
/>
|
||||
<Textarea
|
||||
maxLength={500}
|
||||
maxLength={1000}
|
||||
styles={{
|
||||
label: {
|
||||
color: "white",
|
||||
@@ -139,7 +141,7 @@ export function Donasi_ViewEditKabar({
|
||||
withAsterisk
|
||||
placeholder="Masukan deskripsi kabar"
|
||||
autosize
|
||||
maxRows={4}
|
||||
maxRows={10}
|
||||
minRows={2}
|
||||
value={data.deskripsi}
|
||||
onChange={(val) => {
|
||||
@@ -151,7 +153,7 @@ export function Donasi_ViewEditKabar({
|
||||
/>
|
||||
<ComponentGlobal_InputCountDown
|
||||
lengthInput={data.deskripsi.length}
|
||||
maxInput={500}
|
||||
maxInput={1000}
|
||||
/>
|
||||
|
||||
<Stack spacing={5}>
|
||||
@@ -167,10 +169,7 @@ export function Donasi_ViewEditKabar({
|
||||
</AspectRatio>
|
||||
) : data.imageId === null ? (
|
||||
<Stack justify="center" align="center" h={"100%"}>
|
||||
<IconUpload color="white" />
|
||||
<Text fz={10} fs={"italic"} c={"white"} fw={"bold"}>
|
||||
Upload Gambar
|
||||
</Text>
|
||||
<IconPhoto size={100} />
|
||||
</Stack>
|
||||
) : (
|
||||
<Stack justify="center" align="center" h={"100%"} p={"sm"}>
|
||||
@@ -183,35 +182,12 @@ export function Donasi_ViewEditKabar({
|
||||
</ComponentGlobal_BoxUploadImage>
|
||||
|
||||
{/* Upload Foto */}
|
||||
<Group position="center">
|
||||
<FileButton
|
||||
onChange={async (files: any) => {
|
||||
try {
|
||||
const buffer = URL.createObjectURL(
|
||||
new Blob([new Uint8Array(await files.arrayBuffer())])
|
||||
);
|
||||
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>
|
||||
<Center>
|
||||
<ComponentGlobal_ButtonUploadFileImage
|
||||
onSetFile={setFile}
|
||||
onSetImage={setImg}
|
||||
/>
|
||||
</Center>
|
||||
</Stack>
|
||||
|
||||
<Button
|
||||
|
||||
@@ -1,33 +1,38 @@
|
||||
"use client";
|
||||
|
||||
import { DIRECTORY_ID } from "@/app/lib";
|
||||
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_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_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
||||
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 { clientLogger } from "@/util/clientLogger";
|
||||
import {
|
||||
AspectRatio,
|
||||
Button,
|
||||
FileButton,
|
||||
Group,
|
||||
Center,
|
||||
Image,
|
||||
Stack,
|
||||
Text,
|
||||
TextInput,
|
||||
Textarea,
|
||||
Textarea
|
||||
} from "@mantine/core";
|
||||
import { IconCamera, IconUpload } from "@tabler/icons-react";
|
||||
import { IconPhoto } from "@tabler/icons-react";
|
||||
import _ from "lodash";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
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 [file, setFile] = useState<File | null>(null);
|
||||
const [img, setImg] = useState<any | null>();
|
||||
@@ -58,9 +63,8 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
||||
|
||||
if (!uploadImage.success) {
|
||||
setLoading(false);
|
||||
return ComponentGlobal_NotifikasiPeringatan(
|
||||
"Gagal upload file gambar"
|
||||
);
|
||||
ComponentGlobal_NotifikasiPeringatan("Gagal upload file gambar");
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await Donasi_funCreateKabar({
|
||||
@@ -76,7 +80,6 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
||||
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.back();
|
||||
setLoading(false);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
setLoading(false);
|
||||
@@ -94,21 +97,21 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
||||
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.back();
|
||||
setLoading(false);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
setLoading(false);
|
||||
clientLogger.error("Error upload berita", error);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<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
|
||||
maxLength={100}
|
||||
@@ -128,7 +131,7 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
||||
}}
|
||||
/>
|
||||
<Textarea
|
||||
maxLength={500}
|
||||
maxLength={1000}
|
||||
styles={{
|
||||
label: {
|
||||
color: "white",
|
||||
@@ -138,7 +141,7 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
||||
withAsterisk
|
||||
placeholder="Masukan deskripsi kabar"
|
||||
autosize
|
||||
maxRows={4}
|
||||
maxRows={10}
|
||||
minRows={2}
|
||||
onChange={(val) => {
|
||||
setKabar({
|
||||
@@ -149,7 +152,7 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
||||
/>
|
||||
<ComponentGlobal_InputCountDown
|
||||
lengthInput={kabar.deskripsi.length}
|
||||
maxInput={500}
|
||||
maxInput={1000}
|
||||
/>
|
||||
|
||||
<Stack spacing={5}>
|
||||
@@ -165,44 +168,18 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
||||
</AspectRatio>
|
||||
) : (
|
||||
<Stack justify="center" align="center" h={"100%"}>
|
||||
<IconUpload color="white" />
|
||||
<Text fz={10} fs={"italic"} c={"white"} fw={"bold"}>
|
||||
Upload Gambar
|
||||
</Text>
|
||||
<IconPhoto size={100} />
|
||||
</Stack>
|
||||
)}
|
||||
</ComponentGlobal_BoxUploadImage>
|
||||
|
||||
{/* Upload Foto */}
|
||||
<Group position="center">
|
||||
<FileButton
|
||||
onChange={async (files: any) => {
|
||||
try {
|
||||
const buffer = URL.createObjectURL(
|
||||
new Blob([new Uint8Array(await files.arrayBuffer())])
|
||||
);
|
||||
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>
|
||||
<Center>
|
||||
<ComponentGlobal_ButtonUploadFileImage
|
||||
onSetFile={setFile}
|
||||
onSetImage={setImg}
|
||||
/>
|
||||
</Center>
|
||||
</Stack>
|
||||
|
||||
<Button
|
||||
|
||||
@@ -30,7 +30,6 @@ export async function notifikasiToUser_CreateKabarDonasi({
|
||||
const dataFix = Array.from(data);
|
||||
|
||||
for (let authorId of dataFix) {
|
||||
console.log(authorId);
|
||||
const createNotifikasi = await prisma.notifikasi.create({
|
||||
data: {
|
||||
userRoleId: "1",
|
||||
|
||||
Reference in New Issue
Block a user