Compare commits
5 Commits
nico/9-jun
...
nico/11-ju
| Author | SHA1 | Date | |
|---|---|---|---|
| a1c2821153 | |||
| 9f66b037f9 | |||
| 9e725e2eea | |||
| e4b7418ed3 | |||
| 6d312b7a28 |
@@ -24,6 +24,7 @@
|
|||||||
"@mantine/core": "^7.17.4",
|
"@mantine/core": "^7.17.4",
|
||||||
"@mantine/dates": "^7.17.4",
|
"@mantine/dates": "^7.17.4",
|
||||||
"@mantine/dropzone": "^7.17.0",
|
"@mantine/dropzone": "^7.17.0",
|
||||||
|
"@mantine/form": "^8.1.0",
|
||||||
"@mantine/hooks": "^7.17.4",
|
"@mantine/hooks": "^7.17.4",
|
||||||
"@mantine/tiptap": "^7.17.4",
|
"@mantine/tiptap": "^7.17.4",
|
||||||
"@paljs/types": "^8.1.0",
|
"@paljs/types": "^8.1.0",
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
"biodata": "<p>I.B Surya Prabhawa Manuaba, S.H., M.H., adalah Perbekel Darmasaba periode 2021-2027, seorang advokat, pendiri Mantra Legal Consultants & Advocates, serta aktif di bidang musik dan akademis. Dia menempuh pendidikan hukum di Universitas Udayana dan Universitas Mahasaraswati Denpasar, serta memiliki pengalaman luas di berbagai organisasi dan kepemimpinan.</p>",
|
"biodata": "<p>I.B Surya Prabhawa Manuaba, S.H., M.H., adalah Perbekel Darmasaba periode 2021-2027, seorang advokat, pendiri Mantra Legal Consultants & Advocates, serta aktif di bidang musik dan akademis. Dia menempuh pendidikan hukum di Universitas Udayana dan Universitas Mahasaraswati Denpasar, serta memiliki pengalaman luas di berbagai organisasi dan kepemimpinan.</p>",
|
||||||
"riwayat": "<ul> <li>2021 - 2027: Perbekel Desa Darmasaba</li> <li>2015 - Sekarang: Founder & Managing Director Mantra Legal Consultants & Advocates</li> <li>2020 - Sekarang: Founder Ugawa Record Music Studio</li> <li>2010 - 2016: Dosen Fakultas Hukum Universitas Mahasaraswati Denpasar</li> </ul>",
|
"riwayat": "<ul> <li>2021 - 2027: Perbekel Desa Darmasaba</li> <li>2015 - Sekarang: Founder & Managing Director Mantra Legal Consultants & Advocates</li> <li>2020 - Sekarang: Founder Ugawa Record Music Studio</li> <li>2010 - 2016: Dosen Fakultas Hukum Universitas Mahasaraswati Denpasar</li> </ul>",
|
||||||
"pengalaman": "<ul> <li>1996 – 1997: Ketua OSIS SMP Negeri 1 Abiansemal</li><li>1999 – 2000: Ketua OSIS SMA Negeri 1 Mengwi</li> <li>2008 – 2009: Ketua BEM Universitas Mahasaraswati Denpasar</li> <li>2008 – 2010: Ketua Sekaa Taruna Sila Dharma, Banjar Tengah, Desa Adat Tegal, Darmasaba</li> <li>2020 – Sekarang: Pengurus Young Lawyer Committee Peradi Denpasar</li> <li>2021 – Sekarang: Dewan Kehormatan Himpunan Pengusaha Muda Indonesia (HIPMI) Badung</li> <li>2023 – 2028: Komite Tetap Advokasi – Bidang Hukum dan Regulasi Kamar Dagang dan Industri Badung</li> </ul>",
|
"pengalaman": "<ul> <li>1996 – 1997: Ketua OSIS SMP Negeri 1 Abiansemal</li><li>1999 – 2000: Ketua OSIS SMA Negeri 1 Mengwi</li> <li>2008 – 2009: Ketua BEM Universitas Mahasaraswati Denpasar</li> <li>2008 – 2010: Ketua Sekaa Taruna Sila Dharma, Banjar Tengah, Desa Adat Tegal, Darmasaba</li> <li>2020 – Sekarang: Pengurus Young Lawyer Committee Peradi Denpasar</li> <li>2021 – Sekarang: Dewan Kehormatan Himpunan Pengusaha Muda Indonesia (HIPMI) Badung</li> <li>2023 – 2028: Komite Tetap Advokasi – Bidang Hukum dan Regulasi Kamar Dagang dan Industri Badung</li> </ul>",
|
||||||
"unggulan": "<h3>Pemberdayaan Ekonomi dan UMKM</h3> <ul> <li>Pelatihan dan pendampingan UMKM lokal</li> <li>Program bantuan modal usaha bagi pelaku usaha kecil</li><li>Digitalisasi UMKM untuk meningkatkan pemasaran produk lokal</li></ul>",
|
"unggulan": "<h3>Pemberdayaan Ekonomi dan UMKM</h3> <ul> <li>Pelatihan dan pendampingan UMKM lokal</li> <li>Program bantuan modal usaha bagi pelaku usaha kecil</li><li>Digitalisasi UMKM untuk meningkatkan pemasaran produk lokal</li></ul>"
|
||||||
"imageUrl": "/uploads/seeded-images/profile-ppid/perbekel.png"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
6
prisma/data/ppid/struktur-ppid/strukturPPID.json
Normal file
6
prisma/data/ppid/struktur-ppid/strukturPPID.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id" : "1",
|
||||||
|
"name" : "Struktur PPID"
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -62,11 +62,24 @@ model FileStorage {
|
|||||||
link String
|
link String
|
||||||
Berita Berita[]
|
Berita Berita[]
|
||||||
PotensiDesa PotensiDesa[]
|
PotensiDesa PotensiDesa[]
|
||||||
|
|
||||||
Posyandu Posyandu[]
|
Posyandu Posyandu[]
|
||||||
|
ProfilePPID ProfilePPID[]
|
||||||
|
StrukturPPID StrukturPPID[]
|
||||||
}
|
}
|
||||||
|
|
||||||
//========================================= MENU PPID ========================================= //
|
//========================================= MENU PPID ========================================= //
|
||||||
|
|
||||||
|
//========================================= STRUKTUR PPID ========================================= //
|
||||||
|
model StrukturPPID {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
name String @db.Text
|
||||||
|
image FileStorage? @relation(fields: [imageId], references: [id])
|
||||||
|
imageId String?
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
deletedAt DateTime @default(now())
|
||||||
|
isActive Boolean @default(true)
|
||||||
|
}
|
||||||
// ========================================= VISI MISI PPID ========================================= //
|
// ========================================= VISI MISI PPID ========================================= //
|
||||||
model VisiMisiPPID {
|
model VisiMisiPPID {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
@@ -91,17 +104,18 @@ model DasarHukumPPID {
|
|||||||
|
|
||||||
// ========================================= PROFILE PPID ========================================= //
|
// ========================================= PROFILE PPID ========================================= //
|
||||||
model ProfilePPID {
|
model ProfilePPID {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
name String @db.Text
|
name String @db.Text
|
||||||
biodata String @db.Text
|
biodata String @db.Text
|
||||||
riwayat String @db.Text
|
riwayat String @db.Text
|
||||||
pengalaman String @db.Text
|
pengalaman String @db.Text
|
||||||
unggulan String @db.Text
|
unggulan String @db.Text
|
||||||
imageUrl String?
|
image FileStorage? @relation(fields: [imageId], references: [id])
|
||||||
createdAt DateTime @default(now())
|
imageId String?
|
||||||
updatedAt DateTime @updatedAt
|
createdAt DateTime @default(now())
|
||||||
deletedAt DateTime @default(now())
|
updatedAt DateTime @updatedAt
|
||||||
isActive Boolean @default(true)
|
deletedAt DateTime @default(now())
|
||||||
|
isActive Boolean @default(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================================= DAFTAR INFORMASI PUBLIK ========================================= //
|
// ========================================= DAFTAR INFORMASI PUBLIK ========================================= //
|
||||||
|
|||||||
@@ -6,13 +6,10 @@ import caraMemperolehSalinanInformasi from "./data/list-caraMemperolehSalinanInf
|
|||||||
import jenisInformasiDiminta from "./data/list-jenisInfromasi.json";
|
import jenisInformasiDiminta from "./data/list-jenisInfromasi.json";
|
||||||
import layanan from "./data/list-layanan.json";
|
import layanan from "./data/list-layanan.json";
|
||||||
import potensi from "./data/list-potensi.json";
|
import potensi from "./data/list-potensi.json";
|
||||||
import visiMisiPPID from "./data/ppid/visi-misi-ppid/visimisiPPID.json";
|
|
||||||
import dasarHukumPPID from "./data/ppid/dasar-hukum-ppid/dasarhukumPPID.json";
|
import dasarHukumPPID from "./data/ppid/dasar-hukum-ppid/dasarhukumPPID.json";
|
||||||
import profilePPID from "./data/ppid/profile-ppid/profilePPid.json";
|
import profilePPID from "./data/ppid/profile-ppid/profilePPid.json";
|
||||||
import path from "path";
|
import visiMisiPPID from "./data/ppid/visi-misi-ppid/visimisiPPID.json";
|
||||||
import fs from "fs";
|
import strukturPPID from "./data/ppid/struktur-ppid/strukturPPID.json";
|
||||||
import { mkdir, writeFile } from "fs/promises";
|
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
for (const l of layanan) {
|
for (const l of layanan) {
|
||||||
@@ -31,6 +28,22 @@ import { v4 as uuid } from "uuid";
|
|||||||
|
|
||||||
console.log("layanan success ...");
|
console.log("layanan success ...");
|
||||||
|
|
||||||
|
for (const s of strukturPPID) {
|
||||||
|
await prisma.strukturPPID.upsert({
|
||||||
|
where: {
|
||||||
|
id: s.id,
|
||||||
|
},
|
||||||
|
update: {
|
||||||
|
name: s.name,
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
id: s.id,
|
||||||
|
name: s.name,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
console.log("struktur ppid success ...");
|
||||||
|
|
||||||
for (const p of potensi) {
|
for (const p of potensi) {
|
||||||
await prisma.potensi.upsert({
|
await prisma.potensi.upsert({
|
||||||
where: {
|
where: {
|
||||||
@@ -124,56 +137,29 @@ import { v4 as uuid } from "uuid";
|
|||||||
}
|
}
|
||||||
console.log("cara memperoleh salinan informasi success ...");
|
console.log("cara memperoleh salinan informasi success ...");
|
||||||
|
|
||||||
const seedProfilePPID = async () => {
|
for (const c of profilePPID) {
|
||||||
const targetDir = path.resolve("public", "uploads", "seeded-images", "profile-ppid")
|
await prisma.profilePPID.upsert({
|
||||||
|
where: { id: c.id },
|
||||||
// Buat folder hanya jika belum ada
|
update: {
|
||||||
if (!fs.existsSync(targetDir)) {
|
name: c.name,
|
||||||
await mkdir(targetDir, { recursive: true })
|
biodata: c.biodata,
|
||||||
}
|
riwayat: c.riwayat,
|
||||||
|
pengalaman: c.pengalaman,
|
||||||
for (const c of profilePPID) {
|
unggulan: c.unggulan,
|
||||||
let finalImageUrl = c.imageUrl
|
// imageId tidak di-update
|
||||||
|
},
|
||||||
if (c.imageUrl.startsWith("/uploads/seeded-images/")) {
|
create: {
|
||||||
const filename = path.basename(c.imageUrl)
|
id: c.id,
|
||||||
const seedImagePath = path.resolve("prisma", "seed-images", filename)
|
name: c.name,
|
||||||
|
biodata: c.biodata,
|
||||||
const targetFilename = `${uuid()}_${filename}`
|
riwayat: c.riwayat,
|
||||||
const targetPath = path.join(targetDir, targetFilename)
|
pengalaman: c.pengalaman,
|
||||||
|
unggulan: c.unggulan,
|
||||||
const buffer = fs.readFileSync(seedImagePath)
|
// imageId tidak di-create
|
||||||
await writeFile(targetPath, buffer)
|
},
|
||||||
|
});
|
||||||
finalImageUrl = `/uploads/seeded-images/profile-ppid/${targetFilename}`
|
|
||||||
}
|
|
||||||
|
|
||||||
await prisma.profilePPID.upsert({
|
|
||||||
where: { id: c.id },
|
|
||||||
update: {
|
|
||||||
name: c.name,
|
|
||||||
biodata: c.biodata,
|
|
||||||
riwayat: c.riwayat,
|
|
||||||
pengalaman: c.pengalaman,
|
|
||||||
unggulan: c.unggulan,
|
|
||||||
imageUrl: finalImageUrl,
|
|
||||||
},
|
|
||||||
create: {
|
|
||||||
id: c.id,
|
|
||||||
name: c.name,
|
|
||||||
biodata: c.biodata,
|
|
||||||
riwayat: c.riwayat,
|
|
||||||
pengalaman: c.pengalaman,
|
|
||||||
unggulan: c.unggulan,
|
|
||||||
imageUrl: finalImageUrl,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("✅ profilePPID seeded from JSON with image copying")
|
|
||||||
}
|
}
|
||||||
|
console.log("✅ profilePPID seeded without imageId (editable later via UI)");
|
||||||
await seedProfilePPID()
|
|
||||||
|
|
||||||
for (const v of visiMisiPPID) {
|
for (const v of visiMisiPPID) {
|
||||||
await prisma.visiMisiPPID.upsert({
|
await prisma.visiMisiPPID.upsert({
|
||||||
@@ -210,8 +196,6 @@ import { v4 as uuid } from "uuid";
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log("dasar hukum PPID success ...");
|
console.log("dasar hukum PPID success ...");
|
||||||
|
|
||||||
|
|
||||||
})()
|
})()
|
||||||
.then(() => prisma.$disconnect())
|
.then(() => prisma.$disconnect())
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
|
|||||||
BIN
public/struktur_ppid.png
Normal file
BIN
public/struktur_ppid.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 108 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 275 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 275 KiB |
@@ -1,4 +1,3 @@
|
|||||||
import ApiFetch from "@/lib/api-fetch";
|
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
import { proxy } from "valtio";
|
import { proxy } from "valtio";
|
||||||
@@ -13,11 +12,18 @@ const templateForm = z.object({
|
|||||||
riwayat: z.string().min(3, "Riwayat minimal 3 karakter"),
|
riwayat: z.string().min(3, "Riwayat minimal 3 karakter"),
|
||||||
pengalaman: z.string().min(3, "Pengalaman minimal 3 karakter"),
|
pengalaman: z.string().min(3, "Pengalaman minimal 3 karakter"),
|
||||||
unggulan: z.string().min(3, "Unggulan minimal 3 karakter"),
|
unggulan: z.string().min(3, "Unggulan minimal 3 karakter"),
|
||||||
|
imageId: z.string().min(1, "Gambar wajib dipilih"),
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
const defaultForm = {
|
||||||
* Tipe data ProfilePPID yang digunakan dalam form dan API, berdasarkan Prisma schema.
|
name: "",
|
||||||
*/
|
biodata: "",
|
||||||
|
riwayat: "",
|
||||||
|
pengalaman: "",
|
||||||
|
unggulan: "",
|
||||||
|
imageId: "",
|
||||||
|
};
|
||||||
|
|
||||||
type ProfilePPIDForm = Prisma.ProfilePPIDGetPayload<{
|
type ProfilePPIDForm = Prisma.ProfilePPIDGetPayload<{
|
||||||
select: {
|
select: {
|
||||||
id: true;
|
id: true;
|
||||||
@@ -26,147 +32,170 @@ type ProfilePPIDForm = Prisma.ProfilePPIDGetPayload<{
|
|||||||
riwayat: true;
|
riwayat: true;
|
||||||
pengalaman: true;
|
pengalaman: true;
|
||||||
unggulan: true;
|
unggulan: true;
|
||||||
imageUrl: true;
|
imageId: true;
|
||||||
|
image?: {
|
||||||
|
select: {
|
||||||
|
link: true;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* State utama ProfilePPID yang mencakup fitur:
|
* Improved State Management - Consolidated and more robust
|
||||||
* - Ambil data berdasarkan ID
|
|
||||||
* - Update data
|
|
||||||
* - Upload gambar
|
|
||||||
*/
|
*/
|
||||||
const stateProfilePPID = proxy({
|
const stateProfilePPID = proxy({
|
||||||
/**
|
// Consolidated data management
|
||||||
* Bagian untuk ambil data berdasarkan ID
|
profile: {
|
||||||
*/
|
|
||||||
findById: {
|
|
||||||
data: null as ProfilePPIDForm | null,
|
data: null as ProfilePPIDForm | null,
|
||||||
loading: false,
|
loading: false,
|
||||||
|
error: null as string | null,
|
||||||
|
|
||||||
/**
|
// Single method to load profile data
|
||||||
* Inisialisasi data kosong ke dalam state.
|
|
||||||
*/
|
|
||||||
initialize() {
|
|
||||||
stateProfilePPID.findById.data = {
|
|
||||||
id: '',
|
|
||||||
name: '',
|
|
||||||
biodata: '',
|
|
||||||
riwayat: '',
|
|
||||||
pengalaman: '',
|
|
||||||
unggulan: '',
|
|
||||||
imageUrl: ''
|
|
||||||
} as ProfilePPIDForm;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mengambil data profil berdasarkan ID.
|
|
||||||
* @param {string} id - ID dari profile yang ingin diambil.
|
|
||||||
*/
|
|
||||||
async load(id: string) {
|
async load(id: string) {
|
||||||
try {
|
if (!id) {
|
||||||
stateProfilePPID.findById.loading = true;
|
toast.warn("ID tidak valid");
|
||||||
const res = await ApiFetch.api.ppid.profileppid["find-by-id"].get({
|
return null;
|
||||||
query: { id },
|
}
|
||||||
});
|
|
||||||
|
|
||||||
if (res.status === 200) {
|
this.loading = true;
|
||||||
stateProfilePPID.findById.data = res.data?.data ?? null;
|
this.error = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/ppid/profileppid/${id}`);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
this.data = result.data;
|
||||||
|
return result.data;
|
||||||
} else {
|
} else {
|
||||||
toast.error("Gagal mengambil data profile");
|
throw new Error(result.message || "Gagal mengambil data profile");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error((error as Error).message);
|
const errorMessage = (error as Error).message;
|
||||||
|
this.error = errorMessage;
|
||||||
|
console.error("Load profile error:", errorMessage);
|
||||||
toast.error("Terjadi kesalahan saat mengambil data profile");
|
toast.error("Terjadi kesalahan saat mengambil data profile");
|
||||||
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
stateProfilePPID.findById.loading = false;
|
this.loading = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Reset profile data
|
||||||
|
reset() {
|
||||||
|
this.data = null;
|
||||||
|
this.error = null;
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
// Edit form management
|
||||||
* Bagian untuk update data profile
|
editForm: {
|
||||||
*/
|
id: "",
|
||||||
update: {
|
form: { ...defaultForm },
|
||||||
loading: false,
|
loading: false,
|
||||||
|
error: null as string | null,
|
||||||
|
isReadOnly: false, // Flag untuk data yang tidak bisa diedit
|
||||||
|
|
||||||
/**
|
// Initialize form with profile data
|
||||||
* Melakukan validasi dan menyimpan perubahan data profile ke server.
|
initialize(profileData: ProfilePPIDForm) {
|
||||||
* @param {ProfilePPIDForm} data - Data profil yang akan disimpan.
|
this.id = profileData.id;
|
||||||
*/
|
this.isReadOnly = false; // Semua data bisa diedit
|
||||||
async save(data: ProfilePPIDForm) {
|
this.form = {
|
||||||
const cek = templateForm.safeParse(data);
|
name: profileData.name || "",
|
||||||
|
biodata: profileData.biodata || "",
|
||||||
|
riwayat: profileData.riwayat || "",
|
||||||
|
pengalaman: profileData.pengalaman || "",
|
||||||
|
unggulan: profileData.unggulan || "",
|
||||||
|
imageId: profileData.imageId || "",
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
if (!cek.success) {
|
// Update form field
|
||||||
const errors = cek.error.issues
|
updateField(field: keyof typeof defaultForm, value: string) {
|
||||||
|
this.form[field] = value;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Submit form
|
||||||
|
async submit() {
|
||||||
|
// Validate form
|
||||||
|
const validation = templateForm.safeParse(this.form);
|
||||||
|
|
||||||
|
if (!validation.success) {
|
||||||
|
const errors = validation.error.issues
|
||||||
.map((issue) => `${issue.path.join(".")}: ${issue.message}`)
|
.map((issue) => `${issue.path.join(".")}: ${issue.message}`)
|
||||||
.join(", ");
|
.join(", ");
|
||||||
toast.error(`Form tidak valid: ${errors}`);
|
toast.error(`Form tidak valid: ${errors}`);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
this.loading = true;
|
||||||
stateProfilePPID.update.loading = true;
|
this.error = null;
|
||||||
const res = await ApiFetch.api.ppid.profileppid["update"].post(data);
|
|
||||||
|
|
||||||
if (res.status === 200) {
|
try {
|
||||||
|
const response = await fetch(`/api/ppid/profileppid/${this.id}`, {
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(this.form),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json().catch(() => ({}));
|
||||||
|
throw new Error(errorData.message || `HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
toast.success("Berhasil update profile");
|
toast.success("Berhasil update profile");
|
||||||
await stateProfilePPID.findById.load(data.id);
|
// Refresh profile data
|
||||||
|
await stateProfilePPID.profile.load(this.id);
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
toast.error("Gagal update profile");
|
throw new Error(result.message || "Gagal update profile");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error((error as Error).message);
|
const errorMessage = (error as Error).message;
|
||||||
|
this.error = errorMessage;
|
||||||
|
console.error("Update profile error:", errorMessage);
|
||||||
toast.error("Terjadi kesalahan saat update profile");
|
toast.error("Terjadi kesalahan saat update profile");
|
||||||
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
stateProfilePPID.update.loading = false;
|
this.loading = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Reset form
|
||||||
|
reset() {
|
||||||
|
this.id = "";
|
||||||
|
this.form = { ...defaultForm };
|
||||||
|
this.error = null;
|
||||||
|
this.loading = false;
|
||||||
|
this.isReadOnly = false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
// Helper methods
|
||||||
* Bagian untuk upload gambar profil
|
async loadForEdit(id: string) {
|
||||||
*/
|
const profileData = await this.profile.load(id);
|
||||||
uploadImage: {
|
if (profileData) {
|
||||||
loading: false,
|
this.editForm.initialize(profileData);
|
||||||
|
}
|
||||||
/**
|
return profileData;
|
||||||
* Mengunggah gambar profil berdasarkan ID.
|
|
||||||
* @param {File} file - File gambar yang akan diunggah.
|
|
||||||
* @param {string} id - ID dari profil yang akan diperbarui gambarnya.
|
|
||||||
*/
|
|
||||||
async save(file: File, id: string) {
|
|
||||||
if (!file || !id) {
|
|
||||||
toast.error("File atau ID harus disertakan");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
stateProfilePPID.uploadImage.loading = true;
|
|
||||||
|
|
||||||
const form = new FormData();
|
|
||||||
form.append("file", file);
|
|
||||||
form.append("id", id);
|
|
||||||
|
|
||||||
const res = await ApiFetch.api.ppid.profileppid["edit-img"].post(form);
|
|
||||||
|
|
||||||
if (res.status === 200) {
|
|
||||||
toast.success("Berhasil mengunggah gambar");
|
|
||||||
await stateProfilePPID.findById.load(id);
|
|
||||||
} else {
|
|
||||||
toast.error("Gagal mengunggah gambar");
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error((error as Error).message);
|
|
||||||
toast.error("Terjadi kesalahan saat mengunggah gambar");
|
|
||||||
} finally {
|
|
||||||
stateProfilePPID.uploadImage.loading = false;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
reset() {
|
||||||
|
this.profile.reset();
|
||||||
|
this.editForm.reset();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
export default stateProfilePPID;
|
||||||
* Ekspor state utama ProfilePPID untuk digunakan di komponen lain.
|
|
||||||
*/
|
|
||||||
export default stateProfilePPID;
|
|
||||||
@@ -0,0 +1,169 @@
|
|||||||
|
import { Prisma } from "@prisma/client";
|
||||||
|
import { toast } from "react-toastify";
|
||||||
|
import { proxy } from "valtio";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
const templateForm = z.object({
|
||||||
|
name: z.string().min(3, "Nama minimal 3 karakter"),
|
||||||
|
imageId: z.string().min(1, "Gambar wajib dipilih"),
|
||||||
|
})
|
||||||
|
|
||||||
|
const defaultForm = {
|
||||||
|
name: "",
|
||||||
|
imageId: "",
|
||||||
|
};
|
||||||
|
|
||||||
|
type StrukturPPIDForm = Prisma.StrukturPPIDGetPayload<{
|
||||||
|
select: {
|
||||||
|
id: true;
|
||||||
|
name: true;
|
||||||
|
imageId: true;
|
||||||
|
image?: {
|
||||||
|
select: {
|
||||||
|
link: true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}>;
|
||||||
|
|
||||||
|
const stateStrukturPPID = proxy({
|
||||||
|
struktur: {
|
||||||
|
data: null as StrukturPPIDForm | null,
|
||||||
|
loading: false,
|
||||||
|
error: null as string | null,
|
||||||
|
|
||||||
|
async load(id: string) {
|
||||||
|
if(!id) {
|
||||||
|
toast.warn("ID tidak valid")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
this.loading = true;
|
||||||
|
this.error = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/ppid/strukturppid/${id}`);
|
||||||
|
|
||||||
|
if(!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
if(result.success) {
|
||||||
|
this.data = result.data;
|
||||||
|
return result.data
|
||||||
|
} else {
|
||||||
|
throw new Error(result.message || "Gagal mengambil data struktur")
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const errorMessage = (error as Error).message;
|
||||||
|
this.error = errorMessage;
|
||||||
|
console.error("Load struktur error:", errorMessage);
|
||||||
|
toast.error("Terjadi kesalahan saat mengambil data struktur");
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
reset() {
|
||||||
|
this.data = null;
|
||||||
|
this.error = null;
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
editStruktur: {
|
||||||
|
id: "",
|
||||||
|
form: { ...defaultForm },
|
||||||
|
loading: false,
|
||||||
|
error: null as string | null,
|
||||||
|
isReadOnly: false,
|
||||||
|
|
||||||
|
initialize(strukturData: StrukturPPIDForm) {
|
||||||
|
this.id = strukturData.id;
|
||||||
|
this.isReadOnly = false;
|
||||||
|
this.form = {
|
||||||
|
name: strukturData.name || "",
|
||||||
|
imageId: strukturData.imageId || "",
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
updateField(field: keyof typeof defaultForm, value: string) {
|
||||||
|
this.form[field] = value;
|
||||||
|
},
|
||||||
|
|
||||||
|
async submit() {
|
||||||
|
const validation = templateForm.safeParse(this.form);
|
||||||
|
|
||||||
|
if (!validation.success) {
|
||||||
|
const errors = validation.error.issues
|
||||||
|
.map((issue) => `${issue.path.join(".")}: ${issue.message}`)
|
||||||
|
.join(", ");
|
||||||
|
toast.error(`Form tidak valid: ${errors}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.loading = true;
|
||||||
|
this.error = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/ppid/strukturppid/${this.id}`, {
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(this.form),
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json().catch(() => ({}));
|
||||||
|
throw new Error(errorData.message || `HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
toast.success("Berhasil update struktur");
|
||||||
|
await stateStrukturPPID.struktur.load(this.id);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
throw new Error(result.message || "Gagal update struktur");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const errorMessage = (error as Error).message;
|
||||||
|
this.error = errorMessage;
|
||||||
|
console.error("Update struktur error:", errorMessage);
|
||||||
|
toast.error("Terjadi kesalahan saat update struktur");
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
reset() {
|
||||||
|
this.id = "";
|
||||||
|
this.form = { ...defaultForm };
|
||||||
|
this.error = null;
|
||||||
|
this.loading = false;
|
||||||
|
this.isReadOnly = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async loadForEdit(id: string) {
|
||||||
|
const strukturData = await this.struktur.load(id);
|
||||||
|
if (strukturData) {
|
||||||
|
this.editStruktur.initialize(strukturData);
|
||||||
|
}
|
||||||
|
return strukturData;
|
||||||
|
},
|
||||||
|
|
||||||
|
reset() {
|
||||||
|
this.struktur.reset();
|
||||||
|
this.editStruktur.reset();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export default stateStrukturPPID;
|
||||||
|
|
||||||
@@ -1,11 +1,70 @@
|
|||||||
import React from 'react';
|
'use client'
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Button, Paper, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Text, Title } from '@mantine/core';
|
||||||
|
import { IconDeviceImacCog, IconSearch } from '@tabler/icons-react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import HeaderSearch from '../../_com/header';
|
||||||
|
|
||||||
function Page() {
|
function BeasiswaDesa() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<Box>
|
||||||
beasiswa-desa
|
<HeaderSearch
|
||||||
</div>
|
title='Beasiswa Desa'
|
||||||
|
placeholder='pencarian'
|
||||||
|
searchIcon={<IconSearch size={20} />}
|
||||||
|
/>
|
||||||
|
<ListBeasiswaDesa/>
|
||||||
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Page;
|
function ListBeasiswaDesa() {
|
||||||
|
const router = useRouter();
|
||||||
|
return (
|
||||||
|
<Box py={10}>
|
||||||
|
<Paper bg={colors['white-1']} p="md">
|
||||||
|
<Stack>
|
||||||
|
<Title order={4}>List Beasiswa Desa</Title>
|
||||||
|
<Box style={{overflowX: 'auto'}}>
|
||||||
|
<Table striped withRowBorders withTableBorder style={{minWidth: '700px'}}>
|
||||||
|
<TableThead>
|
||||||
|
<TableTr>
|
||||||
|
<TableTh>Nomor</TableTh>
|
||||||
|
<TableTh>Nama Lengkap</TableTh>
|
||||||
|
<TableTh>Nomor Telepon</TableTh>
|
||||||
|
<TableTh>Email</TableTh>
|
||||||
|
<TableTh>Detail</TableTh>
|
||||||
|
</TableTr>
|
||||||
|
</TableThead>
|
||||||
|
<TableTbody>
|
||||||
|
<TableTr>
|
||||||
|
<TableTd>
|
||||||
|
<Box w={100}>
|
||||||
|
<Text truncate="end" fz={"sm"}>1</Text>
|
||||||
|
</Box>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Text truncate="end" fz={"sm"}>Nama Lengkap</Text>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Text truncate="end" fz={"sm"}>Nomor Telepon</Text>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Text truncate="end" fz={"sm"}>Email</Text>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Button onClick={() => router.push('/admin/pendidikan/beasiswa-desa/detail')}>
|
||||||
|
<IconDeviceImacCog size={25} />
|
||||||
|
</Button>
|
||||||
|
</TableTd>
|
||||||
|
</TableTr>
|
||||||
|
</TableTbody>
|
||||||
|
</Table>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BeasiswaDesa;
|
||||||
|
|||||||
@@ -1,11 +1,74 @@
|
|||||||
import React from 'react';
|
'use client'
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Button, Paper, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Text } from '@mantine/core';
|
||||||
|
import { IconDeviceImacCog, IconSearch } from '@tabler/icons-react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import HeaderSearch from '../../_com/header';
|
||||||
|
import JudulList from '../../_com/judulList';
|
||||||
|
|
||||||
function Page() {
|
function BimbinganBelajarDesa() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<Box>
|
||||||
bimbingan-belajar-desa
|
<HeaderSearch
|
||||||
</div>
|
title='Bimbingan Belajar Desa'
|
||||||
|
placeholder='pencarian'
|
||||||
|
searchIcon={<IconSearch size={20} />}
|
||||||
|
/>
|
||||||
|
<ListBimbinganBelajarDesa/>
|
||||||
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Page;
|
function ListBimbinganBelajarDesa() {
|
||||||
|
const router = useRouter();
|
||||||
|
return (
|
||||||
|
<Box py={10}>
|
||||||
|
<Paper bg={colors['white-1']} p="md">
|
||||||
|
<Stack>
|
||||||
|
<JudulList
|
||||||
|
title='List Bimbingan Belajar Desa'
|
||||||
|
href='/admin/pendidikan/bimbingan-belajar-desa/create'
|
||||||
|
/>
|
||||||
|
<Box style={{overflowX: 'auto'}}>
|
||||||
|
<Table striped withRowBorders withTableBorder style={{minWidth: '700px'}}>
|
||||||
|
<TableThead>
|
||||||
|
<TableTr>
|
||||||
|
<TableTh>Nomor</TableTh>
|
||||||
|
<TableTh>Nama Lengkap</TableTh>
|
||||||
|
<TableTh>Nomor Telepon</TableTh>
|
||||||
|
<TableTh>Email</TableTh>
|
||||||
|
<TableTh>Detail</TableTh>
|
||||||
|
</TableTr>
|
||||||
|
</TableThead>
|
||||||
|
<TableTbody>
|
||||||
|
<TableTr>
|
||||||
|
<TableTd>
|
||||||
|
<Box w={100}>
|
||||||
|
<Text truncate="end" fz={"sm"}>1</Text>
|
||||||
|
</Box>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Text truncate="end" fz={"sm"}>Nama Lengkap</Text>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Text truncate="end" fz={"sm"}>Nomor Telepon</Text>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Text truncate="end" fz={"sm"}>Email</Text>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Button onClick={() => router.push('/admin/pendidikan/bimbingan-belajar-desa/detail')}>
|
||||||
|
<IconDeviceImacCog size={25} />
|
||||||
|
</Button>
|
||||||
|
</TableTd>
|
||||||
|
</TableTr>
|
||||||
|
</TableTbody>
|
||||||
|
</Table>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BimbinganBelajarDesa;
|
||||||
|
|||||||
@@ -1,11 +1,74 @@
|
|||||||
import React from 'react';
|
'use client'
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Button, Paper, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Text } from '@mantine/core';
|
||||||
|
import { IconDeviceImacCog, IconSearch } from '@tabler/icons-react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import HeaderSearch from '../../_com/header';
|
||||||
|
import JudulList from '../../_com/judulList';
|
||||||
|
|
||||||
function Page() {
|
function DataPendidikan() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<Box>
|
||||||
data-pendidikan
|
<HeaderSearch
|
||||||
</div>
|
title='Data Pendidikan'
|
||||||
|
placeholder='pencarian'
|
||||||
|
searchIcon={<IconSearch size={20} />}
|
||||||
|
/>
|
||||||
|
<ListDataPendidikan/>
|
||||||
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Page;
|
function ListDataPendidikan() {
|
||||||
|
const router = useRouter();
|
||||||
|
return (
|
||||||
|
<Box py={10}>
|
||||||
|
<Paper bg={colors['white-1']} p="md">
|
||||||
|
<Stack>
|
||||||
|
<JudulList
|
||||||
|
title='List Data Pendidikan'
|
||||||
|
href='/admin/pendidikan/data-pendidikan/create'
|
||||||
|
/>
|
||||||
|
<Box style={{overflowX: 'auto'}}>
|
||||||
|
<Table striped withRowBorders withTableBorder style={{minWidth: '700px'}}>
|
||||||
|
<TableThead>
|
||||||
|
<TableTr>
|
||||||
|
<TableTh>Nomor</TableTh>
|
||||||
|
<TableTh>Nama Lengkap</TableTh>
|
||||||
|
<TableTh>Nomor Telepon</TableTh>
|
||||||
|
<TableTh>Email</TableTh>
|
||||||
|
<TableTh>Detail</TableTh>
|
||||||
|
</TableTr>
|
||||||
|
</TableThead>
|
||||||
|
<TableTbody>
|
||||||
|
<TableTr>
|
||||||
|
<TableTd>
|
||||||
|
<Box w={100}>
|
||||||
|
<Text truncate="end" fz={"sm"}>1</Text>
|
||||||
|
</Box>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Text truncate="end" fz={"sm"}>Nama Lengkap</Text>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Text truncate="end" fz={"sm"}>Nomor Telepon</Text>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Text truncate="end" fz={"sm"}>Email</Text>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Button onClick={() => router.push('/admin/pendidikan/data-pendidikan/detail')}>
|
||||||
|
<IconDeviceImacCog size={25} />
|
||||||
|
</Button>
|
||||||
|
</TableTd>
|
||||||
|
</TableTr>
|
||||||
|
</TableTbody>
|
||||||
|
</Table>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DataPendidikan;
|
||||||
|
|||||||
@@ -1,11 +1,69 @@
|
|||||||
|
'use client'
|
||||||
|
import { Box, Button, Image, Paper, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Text } from '@mantine/core';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import HeaderSearch from '../../_com/header';
|
||||||
|
import { IconDeviceImacCog, IconSearch } from '@tabler/icons-react';
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import JudulList from '../../_com/judulList';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
function Page() {
|
function InfoSekolahPaud() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<Box>
|
||||||
info-sekolah-paud
|
<HeaderSearch
|
||||||
</div>
|
title='Info Sekolah & PAUD'
|
||||||
|
placeholder='pencarian'
|
||||||
|
searchIcon={<IconSearch size={20} />}
|
||||||
|
/>
|
||||||
|
<ListInfoSekolahPaud/>
|
||||||
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Page;
|
function ListInfoSekolahPaud() {
|
||||||
|
const router = useRouter();
|
||||||
|
return (
|
||||||
|
<Box py={10}>
|
||||||
|
<Paper bg={colors['white-1']} p="md">
|
||||||
|
<Stack>
|
||||||
|
<JudulList
|
||||||
|
title='List Info Sekolah & PAUD'
|
||||||
|
href='/admin/pendidikan/info-sekolah-paud/create'
|
||||||
|
/>
|
||||||
|
<Box style={{overflowX: 'auto'}}>
|
||||||
|
<Table striped withRowBorders withTableBorder style={{minWidth: '700px'}}>
|
||||||
|
<TableThead>
|
||||||
|
<TableTr>
|
||||||
|
<TableTh>Nama Sekolah PAUD</TableTh>
|
||||||
|
<TableTh>Gambar</TableTh>
|
||||||
|
<TableTh>Deskripsi</TableTh>
|
||||||
|
<TableTh>Detail</TableTh>
|
||||||
|
</TableTr>
|
||||||
|
</TableThead>
|
||||||
|
<TableTbody>
|
||||||
|
<TableTr>
|
||||||
|
<TableTd>
|
||||||
|
<Box w={100}>
|
||||||
|
<Text truncate="end" fz={"sm"}>Sekolah PAUD</Text>
|
||||||
|
</Box>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Image w={100} src={"/"} alt="image" />
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>Deskripsi</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Button onClick={() => router.push('/admin/pendidikan/info-sekolah-paud/detail')}>
|
||||||
|
<IconDeviceImacCog size={25} />
|
||||||
|
</Button>
|
||||||
|
</TableTd>
|
||||||
|
</TableTr>
|
||||||
|
</TableTbody>
|
||||||
|
</Table>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default InfoSekolahPaud;
|
||||||
|
|||||||
@@ -1,11 +1,74 @@
|
|||||||
import React from 'react';
|
'use client'
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Button, Paper, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Text } from '@mantine/core';
|
||||||
|
import { IconDeviceImacCog, IconSearch } from '@tabler/icons-react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import HeaderSearch from '../../_com/header';
|
||||||
|
import JudulList from '../../_com/judulList';
|
||||||
|
|
||||||
function Page() {
|
function PendidikanNonFormal() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<Box>
|
||||||
pendidikan-non-formal
|
<HeaderSearch
|
||||||
</div>
|
title='Pendidikan Non Formal'
|
||||||
|
placeholder='pencarian'
|
||||||
|
searchIcon={<IconSearch size={20} />}
|
||||||
|
/>
|
||||||
|
<ListPendidikanNonFormal/>
|
||||||
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Page;
|
function ListPendidikanNonFormal() {
|
||||||
|
const router = useRouter();
|
||||||
|
return (
|
||||||
|
<Box py={10}>
|
||||||
|
<Paper bg={colors['white-1']} p="md">
|
||||||
|
<Stack>
|
||||||
|
<JudulList
|
||||||
|
title='List Pendidikan Non Formal'
|
||||||
|
href='/admin/pendidikan/pendidikan-non-formal/create'
|
||||||
|
/>
|
||||||
|
<Box style={{overflowX: 'auto'}}>
|
||||||
|
<Table striped withRowBorders withTableBorder style={{minWidth: '700px'}}>
|
||||||
|
<TableThead>
|
||||||
|
<TableTr>
|
||||||
|
<TableTh>Nomor</TableTh>
|
||||||
|
<TableTh>Nama Lengkap</TableTh>
|
||||||
|
<TableTh>Nomor Telepon</TableTh>
|
||||||
|
<TableTh>Email</TableTh>
|
||||||
|
<TableTh>Detail</TableTh>
|
||||||
|
</TableTr>
|
||||||
|
</TableThead>
|
||||||
|
<TableTbody>
|
||||||
|
<TableTr>
|
||||||
|
<TableTd>
|
||||||
|
<Box w={100}>
|
||||||
|
<Text truncate="end" fz={"sm"}>1</Text>
|
||||||
|
</Box>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Text truncate="end" fz={"sm"}>Nama Lengkap</Text>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Text truncate="end" fz={"sm"}>Nomor Telepon</Text>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Text truncate="end" fz={"sm"}>Email</Text>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Button onClick={() => router.push('/admin/pendidikan/pendidikan-non-formal/detail')}>
|
||||||
|
<IconDeviceImacCog size={25} />
|
||||||
|
</Button>
|
||||||
|
</TableTd>
|
||||||
|
</TableTr>
|
||||||
|
</TableTbody>
|
||||||
|
</Table>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PendidikanNonFormal;
|
||||||
|
|||||||
@@ -1,11 +1,74 @@
|
|||||||
import React from 'react';
|
'use client'
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Button, Paper, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Text } from '@mantine/core';
|
||||||
|
import { IconDeviceImacCog, IconSearch } from '@tabler/icons-react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import HeaderSearch from '../../_com/header';
|
||||||
|
import JudulList from '../../_com/judulList';
|
||||||
|
|
||||||
function Page() {
|
function PerpustakaanDigital() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<Box>
|
||||||
perpustakaan-digital
|
<HeaderSearch
|
||||||
</div>
|
title='Perpustakaan Digital'
|
||||||
|
placeholder='pencarian'
|
||||||
|
searchIcon={<IconSearch size={20} />}
|
||||||
|
/>
|
||||||
|
<ListPerpustakaanDigital/>
|
||||||
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Page;
|
function ListPerpustakaanDigital() {
|
||||||
|
const router = useRouter();
|
||||||
|
return (
|
||||||
|
<Box py={10}>
|
||||||
|
<Paper bg={colors['white-1']} p="md">
|
||||||
|
<Stack>
|
||||||
|
<JudulList
|
||||||
|
title='List Perpustakaan Digital'
|
||||||
|
href='/admin/pendidikan/perpustakaan-digital/create'
|
||||||
|
/>
|
||||||
|
<Box style={{overflowX: 'auto'}}>
|
||||||
|
<Table striped withRowBorders withTableBorder style={{minWidth: '700px'}}>
|
||||||
|
<TableThead>
|
||||||
|
<TableTr>
|
||||||
|
<TableTh>Nomor</TableTh>
|
||||||
|
<TableTh>Nama Lengkap</TableTh>
|
||||||
|
<TableTh>Nomor Telepon</TableTh>
|
||||||
|
<TableTh>Email</TableTh>
|
||||||
|
<TableTh>Detail</TableTh>
|
||||||
|
</TableTr>
|
||||||
|
</TableThead>
|
||||||
|
<TableTbody>
|
||||||
|
<TableTr>
|
||||||
|
<TableTd>
|
||||||
|
<Box w={100}>
|
||||||
|
<Text truncate="end" fz={"sm"}>1</Text>
|
||||||
|
</Box>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Text truncate="end" fz={"sm"}>Nama Lengkap</Text>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Text truncate="end" fz={"sm"}>Nomor Telepon</Text>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Text truncate="end" fz={"sm"}>Email</Text>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Button onClick={() => router.push('/admin/pendidikan/perpustakaan-digital/detail')}>
|
||||||
|
<IconDeviceImacCog size={25} />
|
||||||
|
</Button>
|
||||||
|
</TableTd>
|
||||||
|
</TableTr>
|
||||||
|
</TableTbody>
|
||||||
|
</Table>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PerpustakaanDigital;
|
||||||
|
|||||||
@@ -1,11 +1,74 @@
|
|||||||
import React from 'react';
|
'use client'
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Button, Paper, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Text } from '@mantine/core';
|
||||||
|
import { IconDeviceImacCog, IconSearch } from '@tabler/icons-react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import HeaderSearch from '../../_com/header';
|
||||||
|
import JudulList from '../../_com/judulList';
|
||||||
|
|
||||||
function Page() {
|
function ProgramPendidikanAnak() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<Box>
|
||||||
program-pendidikan-anak
|
<HeaderSearch
|
||||||
</div>
|
title='Program Pendidikan Anak'
|
||||||
|
placeholder='pencarian'
|
||||||
|
searchIcon={<IconSearch size={20} />}
|
||||||
|
/>
|
||||||
|
<ListProgramPendidikanAnak/>
|
||||||
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Page;
|
function ListProgramPendidikanAnak() {
|
||||||
|
const router = useRouter();
|
||||||
|
return (
|
||||||
|
<Box py={10}>
|
||||||
|
<Paper bg={colors['white-1']} p="md">
|
||||||
|
<Stack>
|
||||||
|
<JudulList
|
||||||
|
title='List Program Pendidikan Anak'
|
||||||
|
href='/admin/pendidikan/program-pendidikan-anak/create'
|
||||||
|
/>
|
||||||
|
<Box style={{overflowX: 'auto'}}>
|
||||||
|
<Table striped withRowBorders withTableBorder style={{minWidth: '700px'}}>
|
||||||
|
<TableThead>
|
||||||
|
<TableTr>
|
||||||
|
<TableTh>Nomor</TableTh>
|
||||||
|
<TableTh>Nama Lengkap</TableTh>
|
||||||
|
<TableTh>Nomor Telepon</TableTh>
|
||||||
|
<TableTh>Email</TableTh>
|
||||||
|
<TableTh>Detail</TableTh>
|
||||||
|
</TableTr>
|
||||||
|
</TableThead>
|
||||||
|
<TableTbody>
|
||||||
|
<TableTr>
|
||||||
|
<TableTd>
|
||||||
|
<Box w={100}>
|
||||||
|
<Text truncate="end" fz={"sm"}>1</Text>
|
||||||
|
</Box>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Text truncate="end" fz={"sm"}>Nama Lengkap</Text>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Text truncate="end" fz={"sm"}>Nomor Telepon</Text>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Text truncate="end" fz={"sm"}>Email</Text>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Button onClick={() => router.push('/admin/pendidikan/program-pendidikan-anak/detail')}>
|
||||||
|
<IconDeviceImacCog size={25} />
|
||||||
|
</Button>
|
||||||
|
</TableTd>
|
||||||
|
</TableTr>
|
||||||
|
</TableTbody>
|
||||||
|
</Table>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ProgramPendidikanAnak;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export function PPIDTextEditor({ onSubmit, onChange, showSubmit = true, initialC
|
|||||||
}, [initialContent, editor]);
|
}, [initialContent, editor]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack>
|
<Stack >
|
||||||
<RichTextEditor editor={editor}>
|
<RichTextEditor editor={editor}>
|
||||||
<RichTextEditor.Toolbar sticky stickyOffset={60}>
|
<RichTextEditor.Toolbar sticky stickyOffset={60}>
|
||||||
<RichTextEditor.ControlsGroup>
|
<RichTextEditor.ControlsGroup>
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ function EditDasarHukum() {
|
|||||||
dasarHukumState.findById.data.content = content;
|
dasarHukumState.findById.data.content = content;
|
||||||
dasarHukumState.update.save(dasarHukumState.findById.data)
|
dasarHukumState.update.save(dasarHukumState.findById.data)
|
||||||
}
|
}
|
||||||
|
router.push('/admin/ppid/dasar-hukum')
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
|
|||||||
@@ -34,15 +34,13 @@ function Page() {
|
|||||||
</Button>
|
</Button>
|
||||||
</GridCol>
|
</GridCol>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Box px={{ base: "md", md: 100 }}>
|
<Box>
|
||||||
<Stack gap={'lg'}>
|
<Stack gap={'lg'}>
|
||||||
<Paper p={"xl"} bg={colors['BG-trans']}>
|
<Paper p={"xl"} bg={colors['BG-trans']}>
|
||||||
<Box px={{ base: 20, md: 50 }} pb={30}>
|
<Box px={{ base: 0, md: 30 }}>
|
||||||
<Text ta={"center"} fz={{ base: "h3", md: "h2" }} fw={"bold"}>
|
<Text ta={"center"} fz={{ base: "h3", md: "h2" }} fw={"bold"} dangerouslySetInnerHTML={{ __html: listDasarHukum.findById.data.judul }} />
|
||||||
{listDasarHukum.findById.data.judul}
|
|
||||||
</Text>
|
|
||||||
</Box>
|
</Box>
|
||||||
<Box px={{ base: 20, md: 50 }}>
|
<Box px={{ base: 0, md: 30 }}>
|
||||||
<Text fz={{ base: "md", md: "h3" }} ta={"justify"} dangerouslySetInnerHTML={{ __html: listDasarHukum.findById.data.content }} />
|
<Text fz={{ base: "md", md: "h3" }} ta={"justify"} dangerouslySetInnerHTML={{ __html: listDasarHukum.findById.data.content }} />
|
||||||
</Box>
|
</Box>
|
||||||
</Paper>
|
</Paper>
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
'use client'
|
||||||
|
import { Box, Text } from '@mantine/core';
|
||||||
|
import EditPPIDEditor from '../../_com/editPPIDEditor';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function Biodata({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
error,
|
||||||
|
}: {
|
||||||
|
value: string;
|
||||||
|
onChange: (val: string) => void;
|
||||||
|
error?: string;
|
||||||
|
}) {
|
||||||
|
|
||||||
|
return (<Box>
|
||||||
|
<Text fw={"bold"}>Biodata</Text>
|
||||||
|
<EditPPIDEditor
|
||||||
|
value={value}
|
||||||
|
onChange={onChange}
|
||||||
|
/>
|
||||||
|
{error && <Text c="red" size="sm">{error}</Text>}
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Biodata;
|
||||||
256
src/app/admin/(dashboard)/ppid/profile-ppid/[id]/page.tsx
Normal file
256
src/app/admin/(dashboard)/ppid/profile-ppid/[id]/page.tsx
Normal file
@@ -0,0 +1,256 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
'use client'
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Alert, Box, Button, Center, FileInput, Group, Image, Paper, Stack, Text, TextInput, Title } from '@mantine/core';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
import stateProfilePPID from '../../../_state/ppid/profile_ppid/profile_PPID';
|
||||||
|
|
||||||
|
import ApiFetch from '@/lib/api-fetch';
|
||||||
|
import { IconAlertCircle, IconArrowBack, IconImageInPicture } from '@tabler/icons-react';
|
||||||
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
|
import { toast } from 'react-toastify';
|
||||||
|
import Biodata from './biodata/biodataForm';
|
||||||
|
import PengalamanOrganisasi from './pengalaman_organisasi/pengalamanForm';
|
||||||
|
import ProgramKerjaUnggulan from './program_kerja_unggulan/programKerjaForm';
|
||||||
|
import RiwayatKarir from './riwayat_karir/riwayatKarirForm';
|
||||||
|
|
||||||
|
function EditProfilePPID() {
|
||||||
|
const allState = useProxy(stateProfilePPID);
|
||||||
|
const params = useParams();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
// UI States
|
||||||
|
const [previewImage, setPreviewImage] = useState<string | null>(null);
|
||||||
|
const [file, setFile] = useState<File | null>(null);
|
||||||
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
|
// Load data on mount
|
||||||
|
useEffect(() => {
|
||||||
|
const loadData = async () => {
|
||||||
|
const id = params?.id as string;
|
||||||
|
if (!id) {
|
||||||
|
toast.error("ID tidak valid");
|
||||||
|
router.push("/admin/ppid/profile-ppid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const profileData = await stateProfilePPID.loadForEdit(id);
|
||||||
|
|
||||||
|
if (profileData && profileData.image?.link) {
|
||||||
|
setPreviewImage(profileData.image.link);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error loading profile:", error);
|
||||||
|
toast.error("Gagal memuat data profile");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loadData();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
stateProfilePPID.editForm.reset(); // cleanup form
|
||||||
|
};
|
||||||
|
}, [params?.id, router]);
|
||||||
|
|
||||||
|
const handleFieldChange = (field: string, value: string) => {
|
||||||
|
stateProfilePPID.editForm.updateField(field as any, value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFileChange = (newFile: File | null) => {
|
||||||
|
if (!newFile) {
|
||||||
|
setFile(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setFile(newFile);
|
||||||
|
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = (event) => {
|
||||||
|
setPreviewImage(event.target?.result as string);
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(newFile);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
if (isSubmitting || !stateProfilePPID.editForm.form.name.trim()) {
|
||||||
|
toast.error("Nama wajib diisi");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsSubmitting(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Upload file jika ada
|
||||||
|
if (file) {
|
||||||
|
const uploadResponse = await ApiFetch.api.fileStorage.create.post({ file, name: file.name });
|
||||||
|
const uploaded = uploadResponse.data?.data;
|
||||||
|
|
||||||
|
if (!uploaded?.id) {
|
||||||
|
toast.error("Gagal upload gambar");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
stateProfilePPID.editForm.form.imageId = uploaded.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Submit form
|
||||||
|
const success = await stateProfilePPID.editForm.submit();
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
toast.success("Berhasil menyimpan perubahan");
|
||||||
|
router.push("/admin/ppid/profile-ppid");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error submitting form:", error);
|
||||||
|
toast.error("Gagal menyimpan profile");
|
||||||
|
} finally {
|
||||||
|
setIsSubmitting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleBack = () => {
|
||||||
|
router.back();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Loading state
|
||||||
|
if (allState.profile.loading) {
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Center h={400}>
|
||||||
|
<Text>Memuat data profile...</Text>
|
||||||
|
</Center>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error state
|
||||||
|
if (allState.profile.error) {
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Stack gap="md">
|
||||||
|
<Button variant="subtle" onClick={handleBack}>
|
||||||
|
<IconArrowBack color={colors['blue-button']} size={20} />
|
||||||
|
</Button>
|
||||||
|
<Alert icon={<IconAlertCircle size={16} />} color="red">
|
||||||
|
<Text fw="bold">Error</Text>
|
||||||
|
<Text>{allState.profile.error}</Text>
|
||||||
|
</Alert>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// No data state
|
||||||
|
if (!allState.profile.data) {
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Stack gap="md">
|
||||||
|
<Button variant="subtle" onClick={handleBack}>
|
||||||
|
<IconArrowBack color={colors['blue-button']} size={20} />
|
||||||
|
</Button>
|
||||||
|
<Alert icon={<IconAlertCircle size={16} />} color="yellow">
|
||||||
|
<Text fw="bold">Data tidak ditemukan</Text>
|
||||||
|
<Text>Profile PPID tidak dapat ditemukan</Text>
|
||||||
|
</Alert>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Stack gap="xs">
|
||||||
|
<Box>
|
||||||
|
<Button variant="subtle" onClick={handleBack}>
|
||||||
|
<IconArrowBack color={colors['blue-button']} size={20} />
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Box>
|
||||||
|
<Paper w={{ base: "100%", md: "50%" }} bg={colors['white-1']} p="md" radius={10}>
|
||||||
|
<Stack gap="xs">
|
||||||
|
<Title order={3}>Edit Profile PPID</Title>
|
||||||
|
|
||||||
|
{/* Nama Field */}
|
||||||
|
<TextInput
|
||||||
|
label={<Text fw="bold">Nama Perbekel</Text>}
|
||||||
|
placeholder="Masukkan nama perbekel"
|
||||||
|
value={allState.editForm.form.name}
|
||||||
|
onChange={(e) => handleFieldChange('name', e.currentTarget.value)}
|
||||||
|
error={!allState.editForm.form.name && "Nama wajib diisi"}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* File Upload */}
|
||||||
|
<FileInput
|
||||||
|
label={<Text fz="sm" fw="bold">Upload Gambar Baru (Opsional)</Text>}
|
||||||
|
value={file}
|
||||||
|
onChange={handleFileChange}
|
||||||
|
accept="image/*"
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Preview Gambar */}
|
||||||
|
<Box>
|
||||||
|
<Text fz="sm" fw="bold" mb="xs">Preview Gambar</Text>
|
||||||
|
{previewImage ? (
|
||||||
|
<Image alt="Profile preview" src={previewImage} w={200} h={200} fit="cover" radius="md" />
|
||||||
|
) : (
|
||||||
|
<Center w={200} h={200} bg="gray.2">
|
||||||
|
<Stack align="center" gap="xs">
|
||||||
|
<IconImageInPicture size={48} color="gray" />
|
||||||
|
<Text size="sm" c="gray">Tidak ada gambar</Text>
|
||||||
|
</Stack>
|
||||||
|
</Center>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{/* Rich Components */}
|
||||||
|
<Biodata
|
||||||
|
value={allState.editForm.form.biodata}
|
||||||
|
onChange={(val) => handleFieldChange('biodata', val)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<RiwayatKarir
|
||||||
|
value={allState.editForm.form.riwayat}
|
||||||
|
onChange={(val) => handleFieldChange('riwayat', val)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<PengalamanOrganisasi
|
||||||
|
value={allState.editForm.form.pengalaman}
|
||||||
|
onChange={(val) => handleFieldChange('pengalaman', val)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ProgramKerjaUnggulan
|
||||||
|
value={allState.editForm.form.unggulan}
|
||||||
|
onChange={(val) => handleFieldChange('unggulan', val)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Submit Button */}
|
||||||
|
<Group>
|
||||||
|
<Button
|
||||||
|
bg={colors['blue-button']}
|
||||||
|
onClick={handleSubmit}
|
||||||
|
loading={isSubmitting || allState.editForm.loading}
|
||||||
|
disabled={!allState.editForm.form.name}
|
||||||
|
>
|
||||||
|
{isSubmitting ? 'Menyimpan...' : 'Simpan Perubahan'}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={handleBack}
|
||||||
|
disabled={isSubmitting || allState.editForm.loading}
|
||||||
|
>
|
||||||
|
Batal
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EditProfilePPID;
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
'use client'
|
||||||
|
import { Box, Text } from '@mantine/core';
|
||||||
|
import EditPPIDEditor from '../../_com/editPPIDEditor';
|
||||||
|
|
||||||
|
|
||||||
|
function PengalamanOrganisasi({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
error,
|
||||||
|
}: {
|
||||||
|
value: string;
|
||||||
|
onChange: (val: string) => void;
|
||||||
|
error?: string;
|
||||||
|
}) {
|
||||||
|
return (<Box>
|
||||||
|
<Text fw={"bold"}>Pengalaman Organisasi</Text>
|
||||||
|
<EditPPIDEditor
|
||||||
|
value={value}
|
||||||
|
onChange={onChange}
|
||||||
|
/>
|
||||||
|
{error && <Text c="red" size="sm">{error}</Text>}
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PengalamanOrganisasi;
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
'use client'
|
||||||
|
import { Box, Text } from '@mantine/core';
|
||||||
|
import EditPPIDEditor from '../../_com/editPPIDEditor';
|
||||||
|
|
||||||
|
function ProgramKerjaUnggulan({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
error,
|
||||||
|
}: {
|
||||||
|
value: string;
|
||||||
|
onChange: (val: string) => void;
|
||||||
|
error?: string;
|
||||||
|
}) {
|
||||||
|
|
||||||
|
return (<Box>
|
||||||
|
<Text fw={"bold"}>Program Kerja Unggulan</Text>
|
||||||
|
<EditPPIDEditor
|
||||||
|
value={value}
|
||||||
|
onChange={onChange}
|
||||||
|
/>
|
||||||
|
{error && <Text c="red" size="sm">{error}</Text>}
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ProgramKerjaUnggulan;
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { Box, Text } from '@mantine/core';
|
||||||
|
import EditPPIDEditor from '../../_com/editPPIDEditor';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function RiwayatKarir({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
error,
|
||||||
|
}: {
|
||||||
|
value: string;
|
||||||
|
onChange: (val: string) => void;
|
||||||
|
error?: string;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Text fw={"bold"}>Riwayat Karir</Text>
|
||||||
|
<EditPPIDEditor
|
||||||
|
value={value}
|
||||||
|
onChange={onChange}
|
||||||
|
/>
|
||||||
|
{error && <Text c="red" size="sm">{error}</Text>}
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RiwayatKarir;
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
const biodata = {
|
|
||||||
id: "1",
|
|
||||||
name: "<p>I.B Surya Prabhawa Manuaba, S.H., M.H.</p>",
|
|
||||||
biodata: "<h2>Biodata</h2> <p>....</p>",
|
|
||||||
riwayat: "<h2>Riwayat Karir</h2> <ul>...</ul>",
|
|
||||||
pengalaman: "<h2>Pengalaman Organisasi</h2> <ul>...</ul>",
|
|
||||||
unggulan: "<h2>Program Kerja Unggulan</h2> <h3>...</h3>",
|
|
||||||
}
|
|
||||||
|
|
||||||
export default biodata
|
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
'use client'
|
||||||
|
import { RichTextEditor, Link } from '@mantine/tiptap';
|
||||||
|
import { useEditor } from '@tiptap/react';
|
||||||
|
import Highlight from '@tiptap/extension-highlight';
|
||||||
|
import StarterKit from '@tiptap/starter-kit';
|
||||||
|
import Underline from '@tiptap/extension-underline';
|
||||||
|
import TextAlign from '@tiptap/extension-text-align';
|
||||||
|
import Superscript from '@tiptap/extension-superscript';
|
||||||
|
import SubScript from '@tiptap/extension-subscript';
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
|
type EditEditorProps = {
|
||||||
|
value: string;
|
||||||
|
onChange: (content: string) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function EditPPIDEditor({ value, onChange }: EditEditorProps) {
|
||||||
|
const editor = useEditor({
|
||||||
|
extensions: [
|
||||||
|
StarterKit,
|
||||||
|
Underline,
|
||||||
|
Link,
|
||||||
|
Superscript,
|
||||||
|
SubScript,
|
||||||
|
Highlight,
|
||||||
|
TextAlign.configure({ types: ['heading', 'paragraph'] }),
|
||||||
|
],
|
||||||
|
onUpdate({ editor }) {
|
||||||
|
onChange(editor.getHTML());
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (editor && value && value !== editor.getHTML()) {
|
||||||
|
editor.commands.setContent(value);
|
||||||
|
}
|
||||||
|
}, [editor, value]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!editor) return;
|
||||||
|
|
||||||
|
const updateHandler = () => onChange(editor.getHTML());
|
||||||
|
editor.on('update', updateHandler);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
editor.off('update', updateHandler);
|
||||||
|
};
|
||||||
|
}, [editor, onChange]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<RichTextEditor editor={editor}>
|
||||||
|
<RichTextEditor.Toolbar sticky stickyOffset="var(--docs-header-height)">
|
||||||
|
{/* Toolbar seperti sebelumnya */}
|
||||||
|
<RichTextEditor.ControlsGroup>
|
||||||
|
<RichTextEditor.Bold />
|
||||||
|
<RichTextEditor.Italic />
|
||||||
|
<RichTextEditor.Underline />
|
||||||
|
<RichTextEditor.Strikethrough />
|
||||||
|
<RichTextEditor.ClearFormatting />
|
||||||
|
<RichTextEditor.Highlight />
|
||||||
|
<RichTextEditor.Code />
|
||||||
|
</RichTextEditor.ControlsGroup>
|
||||||
|
|
||||||
|
<RichTextEditor.ControlsGroup>
|
||||||
|
<RichTextEditor.H1 />
|
||||||
|
<RichTextEditor.H2 />
|
||||||
|
<RichTextEditor.H3 />
|
||||||
|
<RichTextEditor.H4 />
|
||||||
|
</RichTextEditor.ControlsGroup>
|
||||||
|
|
||||||
|
<RichTextEditor.ControlsGroup>
|
||||||
|
<RichTextEditor.Blockquote />
|
||||||
|
<RichTextEditor.Hr />
|
||||||
|
<RichTextEditor.BulletList />
|
||||||
|
<RichTextEditor.OrderedList />
|
||||||
|
<RichTextEditor.Subscript />
|
||||||
|
<RichTextEditor.Superscript />
|
||||||
|
</RichTextEditor.ControlsGroup>
|
||||||
|
|
||||||
|
<RichTextEditor.ControlsGroup>
|
||||||
|
<RichTextEditor.Link />
|
||||||
|
<RichTextEditor.Unlink />
|
||||||
|
</RichTextEditor.ControlsGroup>
|
||||||
|
|
||||||
|
<RichTextEditor.ControlsGroup>
|
||||||
|
<RichTextEditor.AlignLeft />
|
||||||
|
<RichTextEditor.AlignCenter />
|
||||||
|
<RichTextEditor.AlignJustify />
|
||||||
|
<RichTextEditor.AlignRight />
|
||||||
|
</RichTextEditor.ControlsGroup>
|
||||||
|
|
||||||
|
<RichTextEditor.ControlsGroup>
|
||||||
|
<RichTextEditor.Undo />
|
||||||
|
<RichTextEditor.Redo />
|
||||||
|
</RichTextEditor.ControlsGroup>
|
||||||
|
</RichTextEditor.Toolbar>
|
||||||
|
|
||||||
|
<RichTextEditor.Content />
|
||||||
|
</RichTextEditor>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
'use client'
|
|
||||||
import { Box, Group, Text } from '@mantine/core';
|
|
||||||
import { useState } from 'react';
|
|
||||||
|
|
||||||
import ApiFetch from '@/lib/api-fetch';
|
|
||||||
import { Dropzone, MIME_TYPES } from '@mantine/dropzone';
|
|
||||||
import { IconPhoto, IconUpload, IconX } from '@tabler/icons-react';
|
|
||||||
import { useProxy } from 'valtio/utils';
|
|
||||||
import stateProfilePPID from '../../../_state/ppid/profile_ppid/profile_PPID';
|
|
||||||
import { PPIDTextEditor } from '../../_com/PPIDTextEditor';
|
|
||||||
|
|
||||||
function Biodata() {
|
|
||||||
const biodataState = useProxy(stateProfilePPID)
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
|
|
||||||
return (<Box>
|
|
||||||
<Text fw={"bold"}>Biodata</Text>
|
|
||||||
<Dropzone
|
|
||||||
mb={20}
|
|
||||||
onDrop={async (droppedFiles) => {
|
|
||||||
setLoading(true);
|
|
||||||
for (const file of droppedFiles) {
|
|
||||||
await ApiFetch.api.ppid.profileppid["edit-img"].post({
|
|
||||||
file: file,
|
|
||||||
id: biodataState.findById.data?.id,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setLoading(false);
|
|
||||||
if (biodataState.findById.data?.id) {
|
|
||||||
biodataState.findById.load(biodataState.findById.data.id);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
accept={[MIME_TYPES.jpeg, MIME_TYPES.png, MIME_TYPES.webp]}
|
|
||||||
loading={loading}
|
|
||||||
>
|
|
||||||
<Group justify="center" gap="md" mih={150} style={{ pointerEvents: 'none' }}>
|
|
||||||
<Dropzone.Accept>
|
|
||||||
<IconUpload size={50} stroke={1.5} />
|
|
||||||
</Dropzone.Accept>
|
|
||||||
<Dropzone.Reject>
|
|
||||||
<IconX size={50} stroke={1.5} />
|
|
||||||
</Dropzone.Reject>
|
|
||||||
<Dropzone.Idle>
|
|
||||||
<IconPhoto size={50} stroke={1.5} />
|
|
||||||
</Dropzone.Idle>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<Text size="xl" inline>
|
|
||||||
Drag & drop gambar di sini atau klik untuk pilih file
|
|
||||||
</Text>
|
|
||||||
<Text size="sm" c="dimmed" inline mt={7}>
|
|
||||||
Maksimal ukuran file 5MB. Format: JPG, PNG, WebP
|
|
||||||
</Text>
|
|
||||||
</div>
|
|
||||||
</Group>
|
|
||||||
</Dropzone>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<PPIDTextEditor
|
|
||||||
key={biodataState.findById.data?.id ?? 'new'}
|
|
||||||
showSubmit={false}
|
|
||||||
onChange={(val) => {
|
|
||||||
if (biodataState.findById.data) {
|
|
||||||
biodataState.findById.data.biodata = val;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
initialContent={biodataState.findById.data?.biodata ?? ''}
|
|
||||||
/>
|
|
||||||
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Biodata;
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
import colors from '@/con/colors';
|
|
||||||
import { Stack, Skeleton, Paper, Title, Box, Text, Image } from '@mantine/core';
|
|
||||||
import { useShallowEffect } from '@mantine/hooks';
|
|
||||||
import React from 'react';
|
|
||||||
import { useProxy } from 'valtio/utils';
|
|
||||||
import stateProfilePPID from '../../_state/ppid/profile_ppid/profile_PPID';
|
|
||||||
|
|
||||||
function ProfileList() {
|
|
||||||
const allList = useProxy(stateProfilePPID)
|
|
||||||
useShallowEffect(() => {
|
|
||||||
allList.findById.load("1") // Assuming "1" is your default ID, adjust as needed
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
if (!allList.findById.data) return <Stack>
|
|
||||||
{Array.from({ length: 10 }).map((v, k) => <Skeleton key={k} h={40} />)}
|
|
||||||
</Stack>
|
|
||||||
|
|
||||||
const dataArray = Array.isArray(allList.findById.data)
|
|
||||||
? allList.findById.data
|
|
||||||
: [allList.findById.data];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Paper bg={colors['white-1']} p={'md'}>
|
|
||||||
<Stack gap={"xs"}>
|
|
||||||
<Title order={3}>List Profile PPID</Title>
|
|
||||||
{dataArray.map((item) => (
|
|
||||||
<Box key={item.id}>
|
|
||||||
{item.imageUrl && (
|
|
||||||
<Box mb={20}>
|
|
||||||
<Text fw={"bold"} mb={5}>Preview Gambar:</Text>
|
|
||||||
<Image
|
|
||||||
src={item.imageUrl ?? '/perbekel.png'}
|
|
||||||
alt="Profile"
|
|
||||||
w={200}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
<Box>
|
|
||||||
<Text fw={"bold"}>Nama</Text>
|
|
||||||
<Text dangerouslySetInnerHTML={{ __html: item.name }}></Text>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Text fw={"bold"}>Biodata</Text>
|
|
||||||
<Text dangerouslySetInnerHTML={{ __html: item.biodata }}></Text>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Text fw={"bold"}>Riwayat</Text>
|
|
||||||
<Text dangerouslySetInnerHTML={{ __html: item.riwayat }}></Text>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Text fw={"bold"}>Pengalaman</Text>
|
|
||||||
<Text dangerouslySetInnerHTML={{ __html: item.pengalaman }}></Text>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Text fw={"bold"}>Program Kerja Unggulan</Text>
|
|
||||||
<Text dangerouslySetInnerHTML={{ __html: item.unggulan }}></Text>
|
|
||||||
</Box>
|
|
||||||
</Box>
|
|
||||||
))}
|
|
||||||
</Stack>
|
|
||||||
</Paper>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ProfileList;
|
|
||||||
@@ -1,89 +1,120 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import colors from '@/con/colors';
|
import colors from '@/con/colors';
|
||||||
import { Box, Button, Group, Paper, SimpleGrid, Stack, Text, TextInput, Title } from '@mantine/core';
|
import { Box, Button, Center, Divider, Grid, GridCol, Image, Paper, Skeleton, Stack, Text, Title } from '@mantine/core';
|
||||||
import Biodata from './biodata/page';
|
import { useShallowEffect } from '@mantine/hooks';
|
||||||
import PengalamanOrganisasi from './pengalaman_organisasi/page';
|
import { IconEdit } from '@tabler/icons-react';
|
||||||
import RiwayatKarir from './riwayat_karir/page';
|
import { useRouter } from 'next/navigation';
|
||||||
import ProgramKerjaUnggulan from './program_kerja_unggulan/page';
|
|
||||||
import { useProxy } from 'valtio/utils';
|
import { useProxy } from 'valtio/utils';
|
||||||
import stateProfilePPID from '../../_state/ppid/profile_ppid/profile_PPID';
|
import stateProfilePPID from '../../_state/ppid/profile_ppid/profile_PPID';
|
||||||
import { useShallowEffect } from '@mantine/hooks';
|
|
||||||
import ProfileList from './listPage';
|
|
||||||
import { useState } from 'react';
|
|
||||||
import { toast } from 'react-toastify';
|
|
||||||
|
|
||||||
|
|
||||||
function Page() {
|
function Page() {
|
||||||
return (
|
const router = useRouter()
|
||||||
<Box>
|
const allList = useProxy(stateProfilePPID)
|
||||||
<SimpleGrid cols={{ base: 1, md: 2 }}>
|
|
||||||
<ProfileCreate />
|
|
||||||
<ProfileList />
|
|
||||||
</SimpleGrid>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ProfileCreate() {
|
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
|
||||||
const allState = useProxy(stateProfilePPID)
|
|
||||||
|
|
||||||
// Initialize data if it doesn't exist
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
if (!allState.findById.data && isLoading) {
|
allList.profile.load("1") // Assuming "1" is your default ID, adjust as needed
|
||||||
allState.findById.initialize()
|
}, [])
|
||||||
setIsLoading(false)
|
|
||||||
}
|
|
||||||
}, [isLoading])
|
|
||||||
|
|
||||||
const submit = () => {
|
if (!allList.profile.data) {
|
||||||
if (
|
return <Stack>
|
||||||
allState.findById.data?.name &&
|
<Skeleton radius={10} h={800} />
|
||||||
allState.findById.data?.biodata &&
|
</Stack>
|
||||||
allState.findById.data?.riwayat &&
|
|
||||||
allState.findById.data?.pengalaman &&
|
|
||||||
allState.findById.data?.unggulan
|
|
||||||
) {
|
|
||||||
allState.update.save(allState.findById.data)
|
|
||||||
setIsLoading(true)
|
|
||||||
toast.success("success")
|
|
||||||
console.log("[SUBMIT SUCCESS]", JSON.stringify(allState.findById.data, null, 2))
|
|
||||||
allState.findById.initialize()
|
|
||||||
} else {
|
|
||||||
toast.error("error")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dataArray = Array.isArray(allList.profile.data)
|
||||||
|
? allList.profile.data
|
||||||
|
: [allList.profile.data];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Paper bg={colors['white-1']} p={'md'} radius={10}>
|
<Paper bg={colors['white-1']} p={'md'}>
|
||||||
<Stack gap={"xs"}>
|
<Stack gap={"xs"}>
|
||||||
<Title order={3}>Profile PPID</Title>
|
<Grid>
|
||||||
<TextInput
|
<GridCol span={{ base: 12, md: 11 }}>
|
||||||
label={<Text fw={"bold"}>Nama Perbekel</Text>}
|
<Title order={3}>Preview Profile PPID</Title>
|
||||||
placeholder="masukkan nama perbekel"
|
</GridCol>
|
||||||
value={allState.findById.data?.name || ''}
|
<GridCol span={{ base: 12, md: 1 }}>
|
||||||
onChange={(val) => {
|
<Button bg={colors['blue-button']} onClick={() => router.push(`/admin/ppid/profile-ppid/${allList.profile.data?.id}`)}>
|
||||||
if (allState.findById.data) {
|
<IconEdit size={16} />
|
||||||
allState.findById.data.name = val.currentTarget.value
|
</Button>
|
||||||
}
|
</GridCol>
|
||||||
}}
|
</Grid>
|
||||||
/>
|
{dataArray.map((item) => (
|
||||||
<Biodata />
|
<Box key={item.id} >
|
||||||
<RiwayatKarir />
|
<Paper p={"xl"} bg={colors['BG-trans']}>
|
||||||
<PengalamanOrganisasi />
|
<Box px={{ base: "md", md: 100 }}>
|
||||||
<ProgramKerjaUnggulan />
|
<Grid>
|
||||||
<Group>
|
<GridCol span={{ base: 12, md: 12 }}>
|
||||||
<Button
|
<Center>
|
||||||
bg={colors['blue-button']}
|
<Image src={"/api/img/darmasaba-icon.png"} w={{ base: 100, md: 150 }} alt='' />
|
||||||
onClick={submit}
|
</Center>
|
||||||
loading={allState.update.loading}
|
</GridCol>
|
||||||
>
|
<GridCol span={{ base: 12, md: 12 }}>
|
||||||
Submit
|
<Text ta={"center"} fz={{ base: "1.2rem", md: "1.8rem" }} fw={'bold'}>PROFIL PIMPINAN BADAN PUBLIK DESA DARMASABA </Text>
|
||||||
</Button>
|
</GridCol>
|
||||||
</Group>
|
</Grid>
|
||||||
|
</Box>
|
||||||
|
<Divider my={"md"} color={colors['blue-button']} />
|
||||||
|
{/* biodata perbekel */}
|
||||||
|
<Box px={{ base: 0, md: 50 }} pb={30}>
|
||||||
|
<Box pb={20} px={{ base: 0, md: 50 }}>
|
||||||
|
<Paper bg={colors['BG-trans']} w={{ base: "100%", md: "100%" }}>
|
||||||
|
<Stack gap={0}>
|
||||||
|
<Center>
|
||||||
|
<Image
|
||||||
|
pt={{ base: 0, md: 90 }}
|
||||||
|
src={item.image?.link}
|
||||||
|
w={{ base: 250, md: 350 }}
|
||||||
|
alt='Foto Profil PPID'
|
||||||
|
onError={(e) => {
|
||||||
|
e.currentTarget.src = "/perbekel.png";
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Center>
|
||||||
|
<Paper
|
||||||
|
bg={colors['blue-button']}
|
||||||
|
py={20}
|
||||||
|
className="glass3"
|
||||||
|
px={{ base: 10, md: 10 }}
|
||||||
|
|
||||||
|
>
|
||||||
|
<Text ta={"center"} c={colors['white-1']} fw={"bolder"} fz={{ base: "1.2rem", md: "1.6rem" }}>
|
||||||
|
{item.name}
|
||||||
|
</Text>
|
||||||
|
</Paper>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
<Box pt={10}>
|
||||||
|
<Box>
|
||||||
|
<Text fz={{ base: "1.125rem", md: "1.6rem" }} fw={'bold'}>Biodata</Text>
|
||||||
|
<Text fz={{ base: "1rem", md: "1.5rem" }} ta={"justify"} dangerouslySetInnerHTML={{ __html: item.biodata }} />
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Text fz={{ base: "1.125rem", md: "1.6rem" }} fw={'bold'}>Riwayat Karir</Text>
|
||||||
|
<Text fz={{ base: "1rem", md: "1.5rem" }} dangerouslySetInnerHTML={{ __html: item.riwayat }} />
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
<Box pb={30}>
|
||||||
|
<Text fz={{ base: "1.125rem", md: "1.6rem" }} fw={'bold'}>Pengalaman Organisasi</Text>
|
||||||
|
<Box px={20}>
|
||||||
|
<Text fz={{ base: "1rem", md: "1.5rem" }} ta={"justify"} dangerouslySetInnerHTML={{ __html: item.pengalaman }} />
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
<Box pb={20}>
|
||||||
|
<Text fz={{ base: "1.125rem", md: "1.6rem" }} fw={'bold'}>Program Kerja Unggulan</Text>
|
||||||
|
<Box px={20}>
|
||||||
|
<Text fz={{ base: "1rem", md: "1.5rem" }} ta={"justify"} dangerouslySetInnerHTML={{ __html: item.unggulan }} />
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
))}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Paper>
|
</Paper>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default Page;
|
export default Page;
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
'use client'
|
|
||||||
import { Box, Text } from '@mantine/core';
|
|
||||||
import React from 'react';
|
|
||||||
import { useProxy } from 'valtio/utils';
|
|
||||||
import stateProfilePPID from '../../../_state/ppid/profile_ppid/profile_PPID';
|
|
||||||
import { PPIDTextEditor } from '../../_com/PPIDTextEditor';
|
|
||||||
|
|
||||||
function PengalamanOrganisasi() {
|
|
||||||
const pengalamanOrganisasiState = useProxy(stateProfilePPID)
|
|
||||||
return (<Box>
|
|
||||||
<Text fw={"bold"}>Pengalaman Organisasi</Text>
|
|
||||||
<PPIDTextEditor
|
|
||||||
key={pengalamanOrganisasiState.findById.data?.id ?? 'new'}
|
|
||||||
showSubmit={false}
|
|
||||||
onChange={(val) => {
|
|
||||||
if (pengalamanOrganisasiState.findById.data) {
|
|
||||||
pengalamanOrganisasiState.findById.data.pengalaman = val;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
initialContent={pengalamanOrganisasiState.findById.data?.pengalaman ?? ''}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default PengalamanOrganisasi;
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
'use client'
|
|
||||||
import { Box, Text } from '@mantine/core';
|
|
||||||
import React from 'react';
|
|
||||||
import { useProxy } from 'valtio/utils';
|
|
||||||
import stateProfilePPID from '../../../_state/ppid/profile_ppid/profile_PPID';
|
|
||||||
import { PPIDTextEditor } from '../../_com/PPIDTextEditor';
|
|
||||||
|
|
||||||
function ProgramKerjaUnggulan() {
|
|
||||||
const programKerjaUnggulanState = useProxy(stateProfilePPID)
|
|
||||||
return (<Box>
|
|
||||||
<Text fw={"bold"}>Program Kerja Unggulan</Text>
|
|
||||||
<PPIDTextEditor
|
|
||||||
key={programKerjaUnggulanState.findById.data?.id ?? 'new'}
|
|
||||||
showSubmit={false}
|
|
||||||
onChange={(val) => {
|
|
||||||
if (programKerjaUnggulanState.findById.data) {
|
|
||||||
programKerjaUnggulanState.findById.data.unggulan = val;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
initialContent={programKerjaUnggulanState.findById.data?.unggulan ?? ''}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ProgramKerjaUnggulan;
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { Box, Text } from '@mantine/core';
|
|
||||||
import React from 'react';
|
|
||||||
import { useProxy } from 'valtio/utils';
|
|
||||||
import dynamic from 'next/dynamic';
|
|
||||||
import stateProfilePPID from '../../../_state/ppid/profile_ppid/profile_PPID';
|
|
||||||
|
|
||||||
// ini penting
|
|
||||||
const PPIDTextEditor = dynamic(() => import('../../_com/PPIDTextEditor').then(mod => mod.PPIDTextEditor), {
|
|
||||||
ssr: false, // disable server side rendering
|
|
||||||
});
|
|
||||||
function RiwayatKarir() {
|
|
||||||
const riwayatKarirState = useProxy(stateProfilePPID);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Box>
|
|
||||||
<Text fw={"bold"}>Riwayat Karir</Text>
|
|
||||||
<PPIDTextEditor
|
|
||||||
key={riwayatKarirState.findById.data?.id ?? 'new'}
|
|
||||||
showSubmit={false}
|
|
||||||
onChange={(val) => {
|
|
||||||
if (riwayatKarirState.findById.data) {
|
|
||||||
riwayatKarirState.findById.data.riwayat = val;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
initialContent={riwayatKarirState.findById.data?.riwayat ?? ''}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default RiwayatKarir;
|
|
||||||
225
src/app/admin/(dashboard)/ppid/struktur-ppid/[id]/page.tsx
Normal file
225
src/app/admin/(dashboard)/ppid/struktur-ppid/[id]/page.tsx
Normal file
@@ -0,0 +1,225 @@
|
|||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
'use client'
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import {
|
||||||
|
Alert,
|
||||||
|
Box,
|
||||||
|
Button, Center, FileInput, Group, Image, Paper,
|
||||||
|
Stack,
|
||||||
|
Text,
|
||||||
|
TextInput,
|
||||||
|
Title
|
||||||
|
} from '@mantine/core';
|
||||||
|
import { IconAlertCircle, IconArrowBack, IconImageInPicture } from '@tabler/icons-react';
|
||||||
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
import stateStrukturPPID from '../../../_state/ppid/struktur_ppid/struktur_PPID';
|
||||||
|
import { toast } from 'react-toastify';
|
||||||
|
import ApiFetch from '@/lib/api-fetch';
|
||||||
|
|
||||||
|
|
||||||
|
function EditStrukturPPID() {
|
||||||
|
const strukturPPID = useProxy(stateStrukturPPID);
|
||||||
|
const params = useParams();
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
const [previewImage, setPreviewImage] = useState<string | null>(null);
|
||||||
|
const [file, setFile] = useState<File | null>(null);
|
||||||
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadData = async () => {
|
||||||
|
const id = params?.id as string;
|
||||||
|
if (!id) {
|
||||||
|
toast.error("ID tidak valid");
|
||||||
|
router.push("/admin/ppid/struktur-ppid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const profileData = await strukturPPID.loadForEdit(id);
|
||||||
|
|
||||||
|
if (profileData && profileData.image?.link) {
|
||||||
|
setPreviewImage(profileData.image.link);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error loading profile:", error);
|
||||||
|
toast.error("Gagal memuat data profile");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loadData();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
strukturPPID.editStruktur.reset(); // cleanup form
|
||||||
|
};
|
||||||
|
}, [params?.id, router]);
|
||||||
|
|
||||||
|
const handleFieldChange = (field: string, value: string) => {
|
||||||
|
strukturPPID.editStruktur.updateField(field as any, value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFileChange = (newFile: File | null) => {
|
||||||
|
if (!newFile) {
|
||||||
|
setFile(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setFile(newFile);
|
||||||
|
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = (event) => {
|
||||||
|
setPreviewImage(event.target?.result as string);
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(newFile);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
if (isSubmitting || !strukturPPID.editStruktur.form.name.trim()) {
|
||||||
|
toast.error("Nama wajib diisi");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsSubmitting(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Upload file jika ada
|
||||||
|
if (file) {
|
||||||
|
const uploadResponse = await ApiFetch.api.fileStorage.create.post({ file, name: file.name });
|
||||||
|
const uploaded = uploadResponse.data?.data;
|
||||||
|
|
||||||
|
if (!uploaded?.id) {
|
||||||
|
toast.error("Gagal upload gambar");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
strukturPPID.editStruktur.form.imageId = uploaded.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Submit form
|
||||||
|
const success = await strukturPPID.editStruktur.submit();
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
toast.success("Berhasil menyimpan perubahan");
|
||||||
|
router.push("/admin/ppid/struktur-ppid");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error submitting form:", error);
|
||||||
|
toast.error("Gagal menyimpan profile");
|
||||||
|
} finally {
|
||||||
|
setIsSubmitting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleBack = () => {
|
||||||
|
router.back();
|
||||||
|
};
|
||||||
|
|
||||||
|
if (strukturPPID.struktur.loading) {
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Center h={400}>
|
||||||
|
<Text>Memuat data struktur...</Text>
|
||||||
|
</Center>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error state
|
||||||
|
if (strukturPPID.struktur.error) {
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Stack gap="md">
|
||||||
|
<Button variant="subtle" onClick={handleBack}>
|
||||||
|
<IconArrowBack color={colors['blue-button']} size={20} />
|
||||||
|
</Button>
|
||||||
|
<Alert icon={<IconAlertCircle size={16} />} color="red">
|
||||||
|
<Text fw="bold">Error</Text>
|
||||||
|
<Text>{strukturPPID.struktur.error}</Text>
|
||||||
|
</Alert>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// No data state
|
||||||
|
if (!strukturPPID.struktur.data) {
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Stack gap="md">
|
||||||
|
<Button variant="subtle" onClick={handleBack}>
|
||||||
|
<IconArrowBack color={colors['blue-button']} size={20} />
|
||||||
|
</Button>
|
||||||
|
<Alert icon={<IconAlertCircle size={16} />} color="yellow">
|
||||||
|
<Text fw="bold">Data tidak ditemukan</Text>
|
||||||
|
<Text>Profile PPID tidak dapat ditemukan</Text>
|
||||||
|
</Alert>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Stack gap={'xs'}>
|
||||||
|
<Box>
|
||||||
|
<Button
|
||||||
|
variant={'subtle'}
|
||||||
|
onClick={handleBack}
|
||||||
|
>
|
||||||
|
<IconArrowBack color={colors['blue-button']} size={20} />
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Paper bg={colors['white-1']} p={'md'} radius={10} w={{ base: '100%', md: '50%' }}>
|
||||||
|
<Stack gap={'xs'}>
|
||||||
|
<Title order={3}>Edit Struktur PPID</Title>
|
||||||
|
<TextInput
|
||||||
|
value={strukturPPID.editStruktur.form.name}
|
||||||
|
onChange={(e) => handleFieldChange('name', e.currentTarget.value)}
|
||||||
|
label={<Text fz="sm" fw="bold">Judul</Text>}
|
||||||
|
placeholder="Masukkan judul"
|
||||||
|
/>
|
||||||
|
{/* File Upload */}
|
||||||
|
<FileInput
|
||||||
|
label={<Text fz="sm" fw="bold">Upload Gambar Baru (Opsional)</Text>}
|
||||||
|
value={file}
|
||||||
|
onChange={handleFileChange}
|
||||||
|
accept="image/*"
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Preview Gambar */}
|
||||||
|
<Box>
|
||||||
|
<Text fz="sm" fw="bold" mb="xs">Preview Gambar</Text>
|
||||||
|
{previewImage ? (
|
||||||
|
<Image alt="Profile preview" src={previewImage} w={200} h={200} fit="cover" radius="md" />
|
||||||
|
) : (
|
||||||
|
<Center w={200} h={200} bg="gray.2">
|
||||||
|
<Stack align="center" gap="xs">
|
||||||
|
<IconImageInPicture size={48} color="gray" />
|
||||||
|
<Text size="sm" c="gray">Tidak ada gambar</Text>
|
||||||
|
</Stack>
|
||||||
|
</Center>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Group>
|
||||||
|
<Button
|
||||||
|
bg={colors['blue-button']}
|
||||||
|
onClick={handleSubmit}
|
||||||
|
disabled={isSubmitting || strukturPPID.editStruktur.loading}
|
||||||
|
>
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EditStrukturPPID;
|
||||||
@@ -1,10 +1,59 @@
|
|||||||
import React from 'react';
|
'use client'
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Button, Grid, GridCol, Image, Paper, Skeleton, Stack, Text, Title } from '@mantine/core';
|
||||||
|
import { IconEdit } from '@tabler/icons-react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
import stateStrukturPPID from '../../_state/ppid/struktur_ppid/struktur_PPID';
|
||||||
|
import { useShallowEffect } from '@mantine/hooks';
|
||||||
|
|
||||||
function Page() {
|
function Page() {
|
||||||
|
const router = useRouter()
|
||||||
|
const strukturPPID = useProxy(stateStrukturPPID)
|
||||||
|
useShallowEffect(() => {
|
||||||
|
strukturPPID.struktur.load("1")
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
if (!strukturPPID.struktur.data) {
|
||||||
|
return <Stack>
|
||||||
|
<Skeleton radius={10} h={800} />
|
||||||
|
</Stack>
|
||||||
|
}
|
||||||
|
|
||||||
|
const dataArray = Array.isArray(strukturPPID.struktur.data)
|
||||||
|
? strukturPPID.struktur.data
|
||||||
|
: [strukturPPID.struktur.data];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<Paper bg={colors['white-1']} p={'md'}>
|
||||||
struktur-ppid
|
<Stack gap={"xs"}>
|
||||||
</div>
|
<Grid>
|
||||||
|
<GridCol span={{ base: 12, md: 11 }}>
|
||||||
|
<Title order={3}>Preview Struktur PPID</Title>
|
||||||
|
</GridCol>
|
||||||
|
<GridCol span={{ base: 12, md: 1 }}>
|
||||||
|
<Button onClick={() => router.push(`/admin/ppid/struktur-ppid/${strukturPPID.struktur.data?.id}`)} bg={colors['blue-button']}>
|
||||||
|
<IconEdit size={16} />
|
||||||
|
</Button>
|
||||||
|
</GridCol>
|
||||||
|
</Grid>
|
||||||
|
{dataArray.map((item) => (
|
||||||
|
<Paper key={item.id} p={"xl"} bg={colors['BG-trans']}>
|
||||||
|
<Box>
|
||||||
|
<Text fw={"bold"} fz={"h4"}>{item.name}</Text>
|
||||||
|
<Image
|
||||||
|
w={{ base: "100%", md: "100%" }}
|
||||||
|
src={item.image?.link}
|
||||||
|
alt=''
|
||||||
|
onError={(e) => {
|
||||||
|
e.currentTarget.src = "/struktur_ppid.png";
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Paper>
|
||||||
|
))}
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ function VisiMisiPPIDList() {
|
|||||||
<Stack pos={"relative"} gap={"22"}>
|
<Stack pos={"relative"} gap={"22"}>
|
||||||
<Grid>
|
<Grid>
|
||||||
<GridCol span={{ base: 12, md: 11 }}>
|
<GridCol span={{ base: 12, md: 11 }}>
|
||||||
<Title order={2}>Preview Visi Misi PPID</Title>
|
<Title order={3}>Preview Visi Misi PPID</Title>
|
||||||
</GridCol>
|
</GridCol>
|
||||||
<GridCol span={{ base: 12, md: 1 }}>
|
<GridCol span={{ base: 12, md: 1 }}>
|
||||||
<Button bg={colors['blue-button']} onClick={() => router.push('/admin/ppid/visi-misi-ppid/edit')}>
|
<Button bg={colors['blue-button']} onClick={() => router.push('/admin/ppid/visi-misi-ppid/edit')}>
|
||||||
@@ -46,7 +46,7 @@ function VisiMisiPPIDList() {
|
|||||||
</Button>
|
</Button>
|
||||||
</GridCol>
|
</GridCol>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Box px={{ base: "md", md: 100 }}>
|
<Box>
|
||||||
<Stack gap={'lg'}>
|
<Stack gap={'lg'}>
|
||||||
<Paper p={"xl"} bg={colors['BG-trans']}>
|
<Paper p={"xl"} bg={colors['BG-trans']}>
|
||||||
<Box pb={30}>
|
<Box pb={30}>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import PermohonanKeberatanInformasiPublik from "./permohonan_keberatan_informasi
|
|||||||
import ProfilePPID from "./profile_ppid";
|
import ProfilePPID from "./profile_ppid";
|
||||||
import VisiMisiPPID from "./visi_misi_ppid/visi_misi_ppid";
|
import VisiMisiPPID from "./visi_misi_ppid/visi_misi_ppid";
|
||||||
import DasarHukumPPID from "./dasar_hukum";
|
import DasarHukumPPID from "./dasar_hukum";
|
||||||
|
import StrukturPPID from "./struktur_ppid";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ const PPID = new Elysia({ prefix: "/api/ppid", tags: ["PPID"] })
|
|||||||
.use(PermohonanKeberatanInformasiPublik)
|
.use(PermohonanKeberatanInformasiPublik)
|
||||||
.use(VisiMisiPPID)
|
.use(VisiMisiPPID)
|
||||||
.use(DasarHukumPPID)
|
.use(DasarHukumPPID)
|
||||||
|
.use(StrukturPPID)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
import prisma from "@/lib/prisma";
|
|
||||||
import { Context } from "elysia";
|
|
||||||
import { writeFile, unlink } from "fs/promises";
|
|
||||||
import path from "path";
|
|
||||||
import fs from "fs";
|
|
||||||
import { mkdir } from "fs/promises";
|
|
||||||
|
|
||||||
interface ProfilePPIDBody {
|
|
||||||
id: string;
|
|
||||||
file: Blob & { name: string; type: string };
|
|
||||||
}
|
|
||||||
|
|
||||||
export default async function editImageProfilePPID(context: Context<{ body: ProfilePPIDBody }>) {
|
|
||||||
const { id, file } = context.body;
|
|
||||||
|
|
||||||
if (!file || !id) {
|
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
message: "File atau ID harus disertakan",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validasi ekstensi file
|
|
||||||
const allowedTypes = ["image/jpeg", "image/png", "image/webp"];
|
|
||||||
if (!allowedTypes.includes(file.type)) {
|
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
message: "Tipe file tidak diizinkan. Hanya JPG, PNG, atau WEBP",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const bytes = await file.arrayBuffer();
|
|
||||||
const buffer = Buffer.from(bytes);
|
|
||||||
const filename = `${id}_${Date.now()}_${file.name}`;
|
|
||||||
const folderPath = path.resolve("public", "assets", "images", "ppid", "profile-ppid");
|
|
||||||
|
|
||||||
try {
|
|
||||||
await mkdir(folderPath, { recursive: true });
|
|
||||||
|
|
||||||
console.log('Folder path:', folderPath);
|
|
||||||
const filePath = path.join(folderPath, filename);
|
|
||||||
console.log('File path:', filePath);
|
|
||||||
|
|
||||||
await writeFile(filePath, buffer);
|
|
||||||
|
|
||||||
if (!fs.existsSync(filePath)) {
|
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
message: "Failed to write file to disk",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const imageUrl = `/assets/images/ppid/profile-ppid/${filename}`;
|
|
||||||
|
|
||||||
// Hapus file lama (opsional, kalau mau bersih)
|
|
||||||
const oldData = await prisma.profilePPID.findUnique({ where: { id } });
|
|
||||||
if (oldData?.imageUrl) {
|
|
||||||
const oldPath = path.resolve("public", oldData.imageUrl.replace(/^\//, ""));
|
|
||||||
if (fs.existsSync(oldPath)) {
|
|
||||||
await unlink(oldPath).catch(() => {});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update DB
|
|
||||||
await prisma.profilePPID.update({
|
|
||||||
where: { id },
|
|
||||||
data: { imageUrl },
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
message: "Gambar berhasil diunggah",
|
|
||||||
url: imageUrl,
|
|
||||||
};
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error uploading file:', error);
|
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
message: "Gagal mengunggah gambar",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +1,51 @@
|
|||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
import { Context } from "elysia";
|
|
||||||
|
|
||||||
export default async function profilePPIDFindById(context: Context) {
|
export default async function handler(request: Request) {
|
||||||
|
const url = new URL(request.url);
|
||||||
|
const pathSegments = url.pathname.split('/');
|
||||||
|
const id = pathSegments[pathSegments.length - 1];
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "ID tidak boleh kosong",
|
||||||
|
}, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const id = context?.params?.slugs?.[0];
|
if (typeof id !== 'string') {
|
||||||
|
return Response.json({
|
||||||
// If no ID provided, get the first profile
|
success: false,
|
||||||
if (!id) {
|
message: "ID tidak valid",
|
||||||
const data = await prisma.profilePPID.findFirst();
|
}, { status: 400 });
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
data,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await prisma.profilePPID.findUniqueOrThrow({
|
const data = await prisma.profilePPID.findUnique({
|
||||||
where: { id },
|
where: { id },
|
||||||
|
include: {
|
||||||
|
image: true,
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
if (!data) {
|
||||||
success: true,
|
return Response.json({
|
||||||
data,
|
success: false,
|
||||||
};
|
message: "Data tidak ditemukan",
|
||||||
} catch (error) {
|
}, { status: 404 });
|
||||||
console.error("Error fetching profilePPID:", error);
|
}
|
||||||
|
|
||||||
return {
|
return Response.json({
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil mengambil data berdasarkan ID",
|
||||||
|
data,
|
||||||
|
}, { status: 200 });
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Find by ID error:", e);
|
||||||
|
return Response.json({
|
||||||
success: false,
|
success: false,
|
||||||
message: error instanceof Error ? error.message : "Unknown error",
|
message: "Gagal mengambil data: " + (e instanceof Error ? e.message : 'Unknown error'),
|
||||||
};
|
}, {
|
||||||
|
status: 500,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,30 @@
|
|||||||
import Elysia, { t } from "elysia";
|
import Elysia, { t } from "elysia";
|
||||||
import profilePPIDFindById from "./find-by-id";
|
import profilePPIDFindById from "./find-by-id";
|
||||||
import profilePPIDUpdate from "./update";
|
import profilePPIDUpdate from "./update";
|
||||||
import editImageProfilePPID from "./edit-img";
|
|
||||||
|
|
||||||
const ProfilePPID = new Elysia({
|
const ProfilePPID = new Elysia({
|
||||||
prefix: "/profileppid",
|
prefix: "/profileppid",
|
||||||
tags: ["PPID/Profile PPID"]
|
tags: ["PPID/Profile PPID"]
|
||||||
})
|
})
|
||||||
.get("/find-by-id", profilePPIDFindById)
|
.get("/:id", async (context) => {
|
||||||
.post("/update", profilePPIDUpdate, {
|
const response = await profilePPIDFindById(new Request(context.request))
|
||||||
|
return response
|
||||||
|
})
|
||||||
|
.put("/:id", async (context) => {
|
||||||
|
const response = await profilePPIDUpdate(context)
|
||||||
|
return response
|
||||||
|
},
|
||||||
|
{
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
id: t.String(),
|
|
||||||
name: t.String(),
|
name: t.String(),
|
||||||
biodata: t.String(),
|
biodata: t.String(),
|
||||||
riwayat: t.String(),
|
riwayat: t.String(),
|
||||||
pengalaman: t.String(),
|
pengalaman: t.String(),
|
||||||
unggulan: t.String(),
|
unggulan: t.String(),
|
||||||
|
imageId: t.String(),
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
.post("/edit-img", editImageProfilePPID)
|
)
|
||||||
|
|
||||||
|
|
||||||
export default ProfilePPID;
|
export default ProfilePPID;
|
||||||
|
|||||||
@@ -1,38 +1,121 @@
|
|||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
import { Context } from "elysia";
|
import { Context } from "elysia";
|
||||||
|
import fs from "fs/promises";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
type FormCreate = Prisma.ProfilePPIDGetPayload<{
|
type FormUpdate = Prisma.ProfilePPIDGetPayload<{
|
||||||
select: {
|
select: {
|
||||||
id: true;
|
id: true;
|
||||||
name: true;
|
name: true;
|
||||||
biodata: true;
|
biodata: true;
|
||||||
riwayat: true;
|
riwayat: true;
|
||||||
pengalaman: true;
|
pengalaman: true;
|
||||||
unggulan: true;
|
unggulan: true;
|
||||||
}
|
imageId: true;
|
||||||
}>
|
};
|
||||||
|
}>;
|
||||||
export default async function profilePPIDUpdate(context: Context) {
|
export default async function profilePPIDUpdate(context: Context) {
|
||||||
const body = context.body as FormCreate;
|
try {
|
||||||
|
const id = context.params?.id as string;
|
||||||
|
const body = (await context.body) as Omit<FormUpdate, "id">;
|
||||||
|
|
||||||
await prisma.profilePPID.update({
|
const { name, biodata, riwayat, pengalaman, unggulan, imageId } = body;
|
||||||
where: {
|
|
||||||
id: body.id
|
if (!id) {
|
||||||
},
|
return new Response(
|
||||||
data: {
|
JSON.stringify({
|
||||||
name: body.name,
|
success: false,
|
||||||
biodata: body.biodata,
|
message: "ID tidak boleh kosong",
|
||||||
riwayat: body.riwayat,
|
}),
|
||||||
pengalaman: body.pengalaman,
|
{
|
||||||
unggulan: body.unggulan,
|
status: 400,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
const existing = await prisma.profilePPID.findUnique({
|
||||||
|
where: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
image: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
status: 404,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existing.imageId !== imageId) {
|
||||||
|
const oldImage = existing.image;
|
||||||
|
if (oldImage) {
|
||||||
|
try {
|
||||||
|
const filePath = path.join(oldImage.path, oldImage.name);
|
||||||
|
await fs.unlink(filePath);
|
||||||
|
await prisma.fileStorage.delete({
|
||||||
|
where: { id: oldImage.id },
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Gagal hapus gambar lama:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const updated = await prisma.profilePPID.update({
|
||||||
|
where: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
name,
|
||||||
|
biodata,
|
||||||
|
riwayat,
|
||||||
|
pengalaman,
|
||||||
|
imageId,
|
||||||
|
unggulan,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({
|
||||||
success: true,
|
success: true,
|
||||||
message: "Profile PPID Berhasil Dibuat",
|
message: "Profile PPID Berhasil Dibuat",
|
||||||
data: {
|
data: updated,
|
||||||
...body,
|
}),
|
||||||
}
|
{
|
||||||
}
|
status: 200,
|
||||||
}
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error updating profile PPID:", error);
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({
|
||||||
|
success: false,
|
||||||
|
message: "Terjadi kesalahan saat mengupdate profile PPID",
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
status: 500,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
|
export default async function strukturPPIDFindById(request: Request) {
|
||||||
|
const url = new URL(request.url);
|
||||||
|
const pathSegments = url.pathname.split('/');
|
||||||
|
const id = pathSegments[pathSegments.length - 1];
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "ID tidak boleh kosong",
|
||||||
|
}, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (typeof id !== 'string') {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "ID tidak valid",
|
||||||
|
}, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await prisma.strukturPPID.findUnique({
|
||||||
|
where: { id },
|
||||||
|
include: {
|
||||||
|
image: true,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}, { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.json({
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil mengambil data berdasarkan ID",
|
||||||
|
data,
|
||||||
|
}, { status: 200 });
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Find by ID error:", e);
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "Gagal mengambil data: " + (e instanceof Error ? e.message : 'Unknown error'),
|
||||||
|
}, {
|
||||||
|
status: 500,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/app/api/[[...slugs]]/_lib/ppid/struktur_ppid/index.ts
Normal file
23
src/app/api/[[...slugs]]/_lib/ppid/struktur_ppid/index.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import Elysia, { t } from "elysia";
|
||||||
|
import strukturPPIDFindById from "./find-by-id";
|
||||||
|
import strukturPPIDUpdate from "./update";
|
||||||
|
|
||||||
|
const StrukturPPID = new Elysia({
|
||||||
|
prefix: "/strukturppid",
|
||||||
|
tags: ["PPID/Struktur PPID"]
|
||||||
|
})
|
||||||
|
.get("/:id", async (context) => {
|
||||||
|
const response = await strukturPPIDFindById(new Request(context.request))
|
||||||
|
return response
|
||||||
|
})
|
||||||
|
.put("/:id", async (context) => {
|
||||||
|
const response = await strukturPPIDUpdate(context)
|
||||||
|
return response
|
||||||
|
}, {
|
||||||
|
body: t.Object({
|
||||||
|
name: t.String(),
|
||||||
|
imageId: t.String(),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
export default StrukturPPID
|
||||||
116
src/app/api/[[...slugs]]/_lib/ppid/struktur_ppid/update.ts
Normal file
116
src/app/api/[[...slugs]]/_lib/ppid/struktur_ppid/update.ts
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
import path from "path";
|
||||||
|
import fs from "fs/promises";
|
||||||
|
import { Prisma } from "@prisma/client";
|
||||||
|
|
||||||
|
type FormUpdate = Prisma.StrukturPPIDGetPayload<{
|
||||||
|
select: {
|
||||||
|
id: true;
|
||||||
|
name: true;
|
||||||
|
imageId: true;
|
||||||
|
};
|
||||||
|
}>;
|
||||||
|
|
||||||
|
export default async function strukturPPIDUpdate(context: Context) {
|
||||||
|
try {
|
||||||
|
const id = context.params?.id as string;
|
||||||
|
const body = (await context.body) as Omit<FormUpdate, "id">;
|
||||||
|
|
||||||
|
const { name, imageId } = body;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({
|
||||||
|
success: false,
|
||||||
|
message: "ID tidak boleh kosong",
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
status: 400,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await prisma.strukturPPID.findUnique({
|
||||||
|
where: {
|
||||||
|
id
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
image: true,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
status: 404,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existing.imageId !== imageId) {
|
||||||
|
const oldImage = existing.image;
|
||||||
|
if (oldImage) {
|
||||||
|
try {
|
||||||
|
const filePath = path.join(oldImage.path, oldImage.name);
|
||||||
|
await fs.unlink(filePath);
|
||||||
|
await prisma.fileStorage.delete({
|
||||||
|
where: { id: oldImage.id },
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Gagal hapus gambar lama:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const updated = await prisma.strukturPPID.update({
|
||||||
|
where: {
|
||||||
|
id
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
name,
|
||||||
|
imageId,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({
|
||||||
|
success: true,
|
||||||
|
message: "Struktur PPID Berhasil Dibuat",
|
||||||
|
data: updated,
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
status: 200,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error updating struktur PPID:", error);
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({
|
||||||
|
success: false,
|
||||||
|
message: "Terjadi kesalahan saat mengupdate struktur PPID",
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
status: 500,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -9,10 +9,10 @@ import BackButton from '../../desa/layanan/_com/BackButto';
|
|||||||
function Page() {
|
function Page() {
|
||||||
const allList = useProxy(stateProfilePPID)
|
const allList = useProxy(stateProfilePPID)
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
allList.findById.load("1") // Assuming "1" is your default ID, adjust as needed
|
allList.profile.load("1") // Assuming "1" is your default ID, adjust as needed
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
if (!allList.findById.data) return <Stack bg={colors.Bg} py={"xl"} gap={"22"}>
|
if (!allList.profile.data) return <Stack bg={colors.Bg} py={"xl"} gap={"22"}>
|
||||||
<Box px={{ base: 'md', md: 100 }}>
|
<Box px={{ base: 'md', md: 100 }}>
|
||||||
<Skeleton style={{backgroundColor: colors.Bg}} h={40} />
|
<Skeleton style={{backgroundColor: colors.Bg}} h={40} />
|
||||||
</Box>
|
</Box>
|
||||||
@@ -28,9 +28,9 @@ function Page() {
|
|||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
const dataArray = Array.isArray(allList.findById.data)
|
const dataArray = Array.isArray(allList.profile.data)
|
||||||
? allList.findById.data
|
? allList.profile.data
|
||||||
: [allList.findById.data];
|
: [allList.profile.data];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack pos={"relative"} bg={colors.Bg} py={"xl"} gap={"22"}>
|
<Stack pos={"relative"} bg={colors.Bg} py={"xl"} gap={"22"}>
|
||||||
|
|||||||
@@ -13,8 +13,63 @@ import {
|
|||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import ModuleView from "./ModuleView";
|
import ModuleView from "./ModuleView";
|
||||||
import SosmedView from "./SosmedView";
|
import SosmedView from "./SosmedView";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
const getDayOfWeek = () => {
|
||||||
|
const days = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu'];
|
||||||
|
const today = new Date();
|
||||||
|
return days[today.getDay()];
|
||||||
|
}
|
||||||
|
|
||||||
|
const getCurrentTime = () => {
|
||||||
|
const now = new Date();
|
||||||
|
const hours = String(now.getHours()).padStart(2, '0');
|
||||||
|
const minutes = String(now.getMinutes()).padStart(2, '0');
|
||||||
|
return `${hours}:${minutes}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isWorkingHours = (currentTime: string): boolean => {
|
||||||
|
const [openTime, closeTime] = ['08:00', '11:00'];
|
||||||
|
|
||||||
|
const compareTimes = (time1: string, time2: string) => {
|
||||||
|
const [hour1, minute1] = time1.split(':').map(Number);
|
||||||
|
const [hour2, minute2] = time2.split(':').map(Number);
|
||||||
|
|
||||||
|
if (hour1 < hour2) return true;
|
||||||
|
if (hour1 > hour2) return false;
|
||||||
|
return minute1 <= minute2;
|
||||||
|
};
|
||||||
|
return compareTimes(currentTime, closeTime) && !compareTimes(currentTime, openTime);
|
||||||
|
}
|
||||||
|
const getWorkStatus = (day: string, currentTime: string): { status: string; message: string } => {
|
||||||
|
const workingDays = ['Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat'];
|
||||||
|
|
||||||
|
if (!workingDays.includes(day)) {
|
||||||
|
return {
|
||||||
|
status: 'Tutup',
|
||||||
|
message: 'Sabtu - Minggu'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const isOpen = isWorkingHours(currentTime)
|
||||||
|
return isOpen ? { status: 'Buka', message: '08:00 - 16:00' } : { status: 'Tutup', message: '08:00 - 16:00' };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function LandingPage() {
|
function LandingPage() {
|
||||||
|
const [workStatus, setWorkStatus] = useState<{ status: string; message: string }>
|
||||||
|
({ status: '', message: '' });
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const updateWorkStatus = () => {
|
||||||
|
const day = getDayOfWeek();
|
||||||
|
const time = getCurrentTime();
|
||||||
|
const status = getWorkStatus(day, time);
|
||||||
|
setWorkStatus(status);
|
||||||
|
}
|
||||||
|
updateWorkStatus();
|
||||||
|
const intervalId = setInterval(updateWorkStatus, 60 * 1000);
|
||||||
|
return () => clearInterval(intervalId);
|
||||||
|
}, []);
|
||||||
return (
|
return (
|
||||||
<Stack bg={colors["Bg"]}>
|
<Stack bg={colors["Bg"]}>
|
||||||
<Flex
|
<Flex
|
||||||
@@ -135,61 +190,55 @@ function LandingPage() {
|
|||||||
md: 6,
|
md: 6,
|
||||||
}}>
|
}}>
|
||||||
<Box>
|
<Box>
|
||||||
<Text c={colors["white-1"]} fz={"sm"}>
|
<Text c={colors["white-1"]} fz={"sm"}>
|
||||||
Jadwal Kerja
|
Jadwal Kerja
|
||||||
</Text>
|
</Text>
|
||||||
<Paper
|
<Paper
|
||||||
w={{ base: "100%", sm: "100%", md: "auto" }}
|
w={{ base: "100%", sm: "100%", md: "auto" }}
|
||||||
p={5}
|
p={5}
|
||||||
bg={colors["white-1"]}
|
bg={colors["white-1"]}
|
||||||
>
|
>
|
||||||
<Flex justify={"space-between"} align={"center"}>
|
<Flex justify={"space-between"} align={"center"}>
|
||||||
<Box>
|
<Paper
|
||||||
<Text fz={"sm"}>
|
w={{ base: "100%", sm: "100%", md: "auto" }}
|
||||||
Buka
|
p={5}
|
||||||
</Text>
|
bg={colors["white-1"]}
|
||||||
<Text fw={"bold"} fz={"lg"}>
|
>
|
||||||
08:00
|
|
||||||
</Text>
|
<Box>
|
||||||
</Box>
|
<Text fw="bold" fz="sm" c={workStatus.status === 'Buka' ? "black" : "red"}>
|
||||||
<Text fz={"lg"} fw={"bold"}>-</Text>
|
{workStatus.status}
|
||||||
<Box>
|
</Text>
|
||||||
<Text fz={"sm"}>
|
<Text fw="bold" fz="lg" >
|
||||||
Tutup
|
{workStatus.message}
|
||||||
</Text>
|
</Text>
|
||||||
<Text fw={"bold"} fz={"lg"}>
|
</Box>
|
||||||
16:00
|
</Paper>
|
||||||
</Text>
|
</Flex>
|
||||||
</Box>
|
</Paper>
|
||||||
</Flex>
|
</Box>
|
||||||
</Paper>
|
|
||||||
</Box>
|
|
||||||
</GridCol>
|
</GridCol>
|
||||||
|
{/* Edit yang ini */}
|
||||||
<GridCol span={{
|
<GridCol span={{ base: 12, lg: 6, md: 6 }}>
|
||||||
base: 12,
|
<Box>
|
||||||
lg: 6,
|
<Text c={colors["white-1"]} fz={"sm"}>
|
||||||
md: 6,
|
{new Intl.DateTimeFormat('id-ID', {
|
||||||
}}>
|
weekday: 'long',
|
||||||
<Box>
|
year: 'numeric',
|
||||||
<Text c={colors["white-1"]} fz={"sm"}>
|
month: 'long',
|
||||||
Rabu, 10 Maret 2025
|
day: 'numeric'
|
||||||
</Text>
|
}).format(new Date())}
|
||||||
<Paper
|
</Text>
|
||||||
w={{ base: "100%", sm: "100%", md: "auto" }}
|
<Paper bg={colors["white-1"]} p={10}>
|
||||||
p={5}
|
<Text fz="sm" >
|
||||||
bg={colors["white-1"]}
|
Status
|
||||||
>
|
|
||||||
<Box>
|
|
||||||
<Text fz={"sm"}>
|
|
||||||
Buka
|
|
||||||
</Text>
|
</Text>
|
||||||
<Text fw={"bold"} fz={"lg"}>
|
<Text fw="bold" fz="lg" >
|
||||||
Sabtu - Minggu
|
{workStatus.status === 'Buka' ? 'Operasional' : 'Tutup'}
|
||||||
</Text>
|
</Text>
|
||||||
</Box>
|
</Paper>
|
||||||
</Paper>
|
|
||||||
</Box>
|
</Box>
|
||||||
</GridCol>
|
</GridCol>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Paper>
|
</Paper>
|
||||||
|
|||||||
Reference in New Issue
Block a user