Menambahkan seed user
Fix Infinite reload di page ikm dan landing page
This commit is contained in:
10
prisma/data/user/users.json
Normal file
10
prisma/data/user/users.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "cmie1o0zh0002vn132vtzg7hh",
|
||||||
|
"username": "SuperAdmin-Nico",
|
||||||
|
"nomor": "6289647037426",
|
||||||
|
"roleId": 0,
|
||||||
|
"isActive": true,
|
||||||
|
"sessionInvalid": false
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -57,19 +57,41 @@ import roles from "./data/user/roles.json";
|
|||||||
import fileStorage from "./data/file-storage.json";
|
import fileStorage from "./data/file-storage.json";
|
||||||
import jenjangPendidikan from "./data/pendidikan/info-sekolah/jenjang-pendidikan.json";
|
import jenjangPendidikan from "./data/pendidikan/info-sekolah/jenjang-pendidikan.json";
|
||||||
import seedAssets from "./seed_assets";
|
import seedAssets from "./seed_assets";
|
||||||
|
import users from "./data/user/users.json";
|
||||||
import { safeSeedUnique } from "./safeseedUnique";
|
import { safeSeedUnique } from "./safeseedUnique";
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
// =========== USER ===========
|
||||||
|
console.log("🔄 Seeding user...");
|
||||||
|
for (const u of users) {
|
||||||
|
await safeSeedUnique(
|
||||||
|
"user",
|
||||||
|
{ id: u.id },
|
||||||
|
{
|
||||||
|
username: u.username,
|
||||||
|
nomor: u.nomor,
|
||||||
|
roleId: u.roleId.toString(),
|
||||||
|
isActive: u.isActive,
|
||||||
|
sessionInvalid: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("✅ Roles seeded");
|
||||||
// =========== ROLE ===========
|
// =========== ROLE ===========
|
||||||
// In your seed.ts
|
// In your seed.ts
|
||||||
// =========== ROLES ===========
|
// =========== ROLES ===========
|
||||||
console.log("🔄 Seeding roles...");
|
console.log("🔄 Seeding roles...");
|
||||||
for (const r of roles) {
|
for (const r of roles) {
|
||||||
await safeSeedUnique("role", { id: r.id }, {
|
await safeSeedUnique(
|
||||||
name: r.name,
|
"role",
|
||||||
description: r.description,
|
{ id: r.id },
|
||||||
isActive: r.isActive,
|
{
|
||||||
});
|
name: r.name,
|
||||||
|
description: r.description,
|
||||||
|
isActive: r.isActive,
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("✅ Roles seeded");
|
console.log("✅ Roles seeded");
|
||||||
@@ -787,7 +809,9 @@ import { safeSeedUnique } from "./safeseedUnique";
|
|||||||
const flattenedPosisiBumdes = posisiOrganisasi.flat();
|
const flattenedPosisiBumdes = posisiOrganisasi.flat();
|
||||||
|
|
||||||
// ✅ Urutkan berdasarkan hierarki
|
// ✅ Urutkan berdasarkan hierarki
|
||||||
const sortedPosisiBumdes = flattenedPosisiBumdes.sort((a, b) => a.hierarki - b.hierarki);
|
const sortedPosisiBumdes = flattenedPosisiBumdes.sort(
|
||||||
|
(a, b) => a.hierarki - b.hierarki
|
||||||
|
);
|
||||||
|
|
||||||
for (const p of sortedPosisiBumdes) {
|
for (const p of sortedPosisiBumdes) {
|
||||||
console.log(`Seeding: ${p.nama} (id: ${p.id}, parent: ${p.parentId})`);
|
console.log(`Seeding: ${p.nama} (id: ${p.id}, parent: ${p.parentId})`);
|
||||||
@@ -867,7 +891,7 @@ import { safeSeedUnique } from "./safeseedUnique";
|
|||||||
// Add IDs to the kategoriKegiatan data
|
// Add IDs to the kategoriKegiatan data
|
||||||
const kategoriKegiatan = kategoriKegiatanData.map((k, index) => ({
|
const kategoriKegiatan = kategoriKegiatanData.map((k, index) => ({
|
||||||
...k,
|
...k,
|
||||||
id: `kategori-${index + 1}`
|
id: `kategori-${index + 1}`,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
for (const k of kategoriKegiatan) {
|
for (const k of kategoriKegiatan) {
|
||||||
@@ -1159,7 +1183,6 @@ import { safeSeedUnique } from "./safeseedUnique";
|
|||||||
|
|
||||||
// seed assets
|
// seed assets
|
||||||
await seedAssets();
|
await seedAssets();
|
||||||
|
|
||||||
})()
|
})()
|
||||||
.then(() => prisma.$disconnect())
|
.then(() => prisma.$disconnect())
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ const state = useProxy(indeksKepuasanState.responden);
|
|||||||
indeksKepuasanState.jenisKelaminResponden.findMany.load()
|
indeksKepuasanState.jenisKelaminResponden.findMany.load()
|
||||||
indeksKepuasanState.pilihanRatingResponden.findMany.load()
|
indeksKepuasanState.pilihanRatingResponden.findMany.load()
|
||||||
indeksKepuasanState.kelompokUmurResponden.findMany.load()
|
indeksKepuasanState.kelompokUmurResponden.findMany.load()
|
||||||
})
|
},[])
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ function Kepuasan() {
|
|||||||
indeksKepuasanState.jenisKelaminResponden.findMany.load()
|
indeksKepuasanState.jenisKelaminResponden.findMany.load()
|
||||||
indeksKepuasanState.pilihanRatingResponden.findMany.load()
|
indeksKepuasanState.pilihanRatingResponden.findMany.load()
|
||||||
indeksKepuasanState.kelompokUmurResponden.findMany.load()
|
indeksKepuasanState.kelompokUmurResponden.findMany.load()
|
||||||
})
|
},[])
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -59,6 +59,35 @@ const getWorkStatus = (day: string, currentTime: string): { status: string; mess
|
|||||||
: { status: "Tutup", message: "08:00 - 17:00" };
|
: { status: "Tutup", message: "08:00 - 17:00" };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Skeleton component untuk Social Media
|
||||||
|
const SosmedSkeleton = () => (
|
||||||
|
<Flex gap="md" justify="center" wrap="wrap">
|
||||||
|
{[1, 2, 3, 4].map((i) => (
|
||||||
|
<Skeleton key={i} height={56} width={56} circle />
|
||||||
|
))}
|
||||||
|
</Flex>
|
||||||
|
);
|
||||||
|
|
||||||
|
// Skeleton component untuk Profile
|
||||||
|
const ProfileSkeleton = () => (
|
||||||
|
<Card
|
||||||
|
radius="xl"
|
||||||
|
bg={colors.grey[1]}
|
||||||
|
p="lg"
|
||||||
|
shadow="xl"
|
||||||
|
w={{ base: "100%", md: "35%" }}
|
||||||
|
style={{ height: "fit-content" }}
|
||||||
|
>
|
||||||
|
<Stack gap="lg" align="center">
|
||||||
|
<Skeleton height={300} width="100%" radius="lg" />
|
||||||
|
<Stack gap="xs" w="100%" align="center">
|
||||||
|
<Skeleton height={20} width="60%" />
|
||||||
|
<Skeleton height={32} width="80%" />
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
|
||||||
function LandingPage() {
|
function LandingPage() {
|
||||||
const [socialMedia, setSocialMedia] = useState<
|
const [socialMedia, setSocialMedia] = useState<
|
||||||
Prisma.MediaSosialGetPayload<{ include: { image: true } }>[]
|
Prisma.MediaSosialGetPayload<{ include: { image: true } }>[]
|
||||||
@@ -66,9 +95,8 @@ function LandingPage() {
|
|||||||
const [profile, setProfile] = useState<
|
const [profile, setProfile] = useState<
|
||||||
Prisma.PejabatDesaGetPayload<{ include: { image: true } }> | null
|
Prisma.PejabatDesaGetPayload<{ include: { image: true } }> | null
|
||||||
>(null);
|
>(null);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoadingSosmed, setIsLoadingSosmed] = useState(true);
|
||||||
|
const [isLoadingProfile, setIsLoadingProfile] = useState(true);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchSocialMedia = async () => {
|
const fetchSocialMedia = async () => {
|
||||||
@@ -86,7 +114,7 @@ function LandingPage() {
|
|||||||
} catch {
|
} catch {
|
||||||
setSocialMedia([]);
|
setSocialMedia([]);
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoadingSosmed(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -98,6 +126,8 @@ function LandingPage() {
|
|||||||
setProfile(result.data || null);
|
setProfile(result.data || null);
|
||||||
} catch {
|
} catch {
|
||||||
setProfile(null);
|
setProfile(null);
|
||||||
|
} finally {
|
||||||
|
setIsLoadingProfile(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -189,8 +219,8 @@ function LandingPage() {
|
|||||||
|
|
||||||
<ModuleView />
|
<ModuleView />
|
||||||
|
|
||||||
{isLoading ? (
|
{isLoadingSosmed ? (
|
||||||
<Skeleton height={32} width="100%" />
|
<SosmedSkeleton />
|
||||||
) : socialMedia.length > 0 ? (
|
) : socialMedia.length > 0 ? (
|
||||||
<SosmedView data={socialMedia} />
|
<SosmedView data={socialMedia} />
|
||||||
) : (
|
) : (
|
||||||
@@ -207,19 +237,27 @@ function LandingPage() {
|
|||||||
</Card>
|
</Card>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
{isLoading ? (
|
{isLoadingProfile ? (
|
||||||
<Skeleton height={300} width="100%" radius="lg" />
|
<ProfileSkeleton />
|
||||||
) : profile ? (
|
) : profile ? (
|
||||||
<ProfileView data={profile} />
|
<ProfileView data={profile} />
|
||||||
) : (
|
) : (
|
||||||
<Center w="100%">
|
<Card
|
||||||
<Text c="dimmed">Informasi profil belum tersedia</Text>
|
radius="xl"
|
||||||
</Center>
|
bg={colors.grey[1]}
|
||||||
|
p="lg"
|
||||||
|
shadow="xl"
|
||||||
|
w={{ base: "100%", md: "35%" }}
|
||||||
|
style={{ height: "fit-content" }}
|
||||||
|
>
|
||||||
|
<Center h={300}>
|
||||||
|
<Text c="dimmed">Informasi profil belum tersedia</Text>
|
||||||
|
</Center>
|
||||||
|
</Card>
|
||||||
)}
|
)}
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default LandingPage;
|
export default LandingPage;
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
'use client'
|
'use client'
|
||||||
import DesaAntiKorupsi from "@/app/darmasaba/_com/main-page/desaantikorupsi";
|
import DesaAntiKorupsi from "@/app/darmasaba/_com/main-page/desaantikorupsi";
|
||||||
import Kepuasan from "@/app/darmasaba/_com/main-page/kepuasan";
|
import Kepuasan from "@/app/darmasaba/_com/main-page/kepuasan";
|
||||||
@@ -13,32 +14,34 @@ import Apbdes from "./_com/main-page/apbdes";
|
|||||||
import Prestasi from "./_com/main-page/prestasi";
|
import Prestasi from "./_com/main-page/prestasi";
|
||||||
import ScrollToTopButton from "./_com/scrollToTopButton";
|
import ScrollToTopButton from "./_com/scrollToTopButton";
|
||||||
|
|
||||||
import NewsReaderLanding from "./_com/NewsReaderalanding";
|
import { useEffect, useMemo } from "react";
|
||||||
import ModernNewsNotification from "./_com/ModernNeewsNotification";
|
import { useSnapshot } from "valtio";
|
||||||
import { useMemo } from "react";
|
|
||||||
import { useProxy } from "valtio/utils";
|
|
||||||
import stateDashboardBerita from "../admin/(dashboard)/_state/desa/berita";
|
import stateDashboardBerita from "../admin/(dashboard)/_state/desa/berita";
|
||||||
import stateDesaPengumuman from "../admin/(dashboard)/_state/desa/pengumuman";
|
import stateDesaPengumuman from "../admin/(dashboard)/_state/desa/pengumuman";
|
||||||
import { useEffect } from "react";
|
import ModernNewsNotification from "./_com/ModernNeewsNotification";
|
||||||
|
import NewsReaderLanding from "./_com/NewsReaderalanding";
|
||||||
|
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
const featured = useProxy(stateDashboardBerita.berita.findFirst);
|
const snap1 = useSnapshot(stateDashboardBerita.berita.findFirst);
|
||||||
|
const snap2 = useSnapshot(stateDesaPengumuman.pengumuman.findFirst);
|
||||||
|
|
||||||
|
const featured = snap1;
|
||||||
|
const pengumuman = snap2;
|
||||||
const loadingFeatured = featured.loading;
|
const loadingFeatured = featured.loading;
|
||||||
const pengumuman = useProxy(stateDesaPengumuman.pengumuman.findFirst);
|
|
||||||
const loadingPengumuman = pengumuman.loading;
|
const loadingPengumuman = pengumuman.loading;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!featured.data && !loadingFeatured) {
|
if (!featured.data && !loadingFeatured) {
|
||||||
stateDashboardBerita.berita.findFirst.load();
|
stateDashboardBerita.berita.findFirst.load();
|
||||||
}
|
}
|
||||||
}, [featured.data, loadingFeatured]);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!pengumuman.data && !loadingPengumuman) {
|
if (!pengumuman.data && !loadingPengumuman) {
|
||||||
stateDesaPengumuman.pengumuman.findFirst.load();
|
stateDesaPengumuman.pengumuman.findFirst.load();
|
||||||
}
|
}
|
||||||
}, [pengumuman.data, loadingPengumuman]);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
const newsData = useMemo(() => {
|
const newsData = useMemo(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user