Deskripsi:
- Di beranda diganti menggunakan API
- Skeleton beranda
- V 1.2.25
This commit is contained in:
2024-12-12 14:46:06 +08:00
parent 80b6d35fe9
commit d1f7966123
15 changed files with 253 additions and 168 deletions

View File

@@ -56,10 +56,8 @@ export function Profile_ComponentCreateNewProfile({
dirId: DIRECTORY_ID.profile_foto,
});
if (!uploadPhoto.success) {
setLoading(false);
return ComponentGlobal_NotifikasiPeringatan(
"Gagal upload foto profile"
);
ComponentGlobal_NotifikasiPeringatan("Gagal upload foto profile");
return;
}
const uploadBackground = await funGlobal_UploadToStorage({
@@ -67,10 +65,8 @@ export function Profile_ComponentCreateNewProfile({
dirId: DIRECTORY_ID.profile_background,
});
if (!uploadBackground.success) {
setLoading(false);
return ComponentGlobal_NotifikasiPeringatan(
"Gagal upload background profile"
);
ComponentGlobal_NotifikasiPeringatan("Gagal upload background profile");
return;
}
const create = await funCreateNewProfile({
@@ -78,15 +74,24 @@ export function Profile_ComponentCreateNewProfile({
imageId: uploadPhoto.data.id,
imageBackgroundId: uploadBackground.data.id,
});
if (create.status === 201) {
ComponentGlobal_NotifikasiBerhasil("Berhasil membuat profile", 3000);
router.push(RouterHome.main_home, { scroll: false });
} else {
ComponentGlobal_NotifikasiGagal(create.message);
setLoading(false);
}
if (create.status === 400) {
ComponentGlobal_NotifikasiGagal(create.message);
}
if (create.status === 500) {
ComponentGlobal_NotifikasiGagal(create.message);
}
} catch (error) {
console.log(error);
console.log("Terjadi kesalahan", error);
} finally {
setLoading(false);
}
}

View File

@@ -1,14 +1,10 @@
"use server";
import prisma from "@/app/lib/prisma";
import { MODEL_PROFILE } from "../model/interface";
import _ from "lodash";
import { v4 } from "uuid";
import fs from "fs";
import { revalidatePath } from "next/cache";
import { RouterHome } from "@/app/lib/router_hipmi/router_home";
import { Prisma } from "@prisma/client";
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import { Prisma } from "@prisma/client";
import { revalidatePath } from "next/cache";
export default async function funCreateNewProfile({
data,
@@ -19,33 +15,53 @@ export default async function funCreateNewProfile({
imageId: string;
imageBackgroundId: string;
}) {
const userLoginId = await funGetUserIdByToken();
try {
const userLoginId = await funGetUserIdByToken();
const findEmail = await prisma.profile.findUnique({
where: {
email: data.email,
},
});
if (!userLoginId) {
return { status: 400, message: "User tidak terautentikasi" }; // Validasi user login
}
if (findEmail) return { status: 400, message: "Email telah digunakan" };
const findEmail = await prisma.profile.findUnique({
where: {
email: data.email,
},
});
const createProfile = await prisma.profile.create({
data: {
userId: userLoginId,
name: data.name,
email: data.email,
alamat: data.alamat,
jenisKelamin: data.jenisKelamin,
imageId: imageId,
imageBackgroundId: imageBackgroundId,
},
});
if (findEmail) {
return { status: 400, message: "Email telah digunakan" };
}
if (!createProfile) return { status: 400, message: "Gagal membuat profile" };
revalidatePath(RouterHome.main_home);
const createProfile = await prisma.profile.create({
data: {
userId: userLoginId,
name: data.name,
email: data.email,
alamat: data.alamat,
jenisKelamin: data.jenisKelamin,
imageId: imageId,
imageBackgroundId: imageBackgroundId,
},
});
return {
status: 201,
message: "Berhasil",
};
if (!createProfile) {
return { status: 400, message: "Gagal membuat profile" };
}
// Revalidate cache halaman home
try {
revalidatePath(RouterHome.main_home);
} catch (cacheError) {
console.error("Cache revalidation failed:", cacheError);
// Tidak membuat fungsi gagal, cukup log error cache
}
return {
status: 201,
message: "Berhasil",
};
} catch (error) {
console.error("Error creating profile:", error);
return { status: 500, message: "Terjadi kesalahan pada server" };
}
}