Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update production #248

Merged
merged 9 commits into from
Jul 11, 2024
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ yarn-debug.log*
yarn-error.log*

# local env files
.env*.local
.env*

# vercel
.vercel
Expand Down
File renamed without changes.
28 changes: 12 additions & 16 deletions src/actions/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,20 @@ export const updateUserWithId = async (id: string | null, data: FormData) => {
},
});
if (!create) throw new Error("Update failed");
} else if (id) {
const findUserWithId = await findUser({ id });
if (findUserWithId) {
const update = await updateUser(
{ id: id ?? findUserWithId.id },
{
email: email ?? findUserWithId.email,
name: name ?? findUserWithId.name,
role: role ?? findUserWithId.role,
userAuth: {
update: { password: password ? encrypt(password) : undefined },
},
},
);
if (!update) throw new Error("Update failed");
} else throw new Error("Update failed");
} else if (id || findEmail) {
const update = await updateUser(id ? { id } : { email }, {
email: email ?? undefined,
name: name ?? undefined,
role: role ?? undefined,
userAuth: {
update: { password: password ? encrypt(password) : undefined },
},
});
if (!update) throw new Error("Update failed");
}

revalidatePath("/admin/users");
revalidatePath("/", "layout");
return { message: "Berhasil disimpan!", error: false };
} catch (e) {
console.error(e);
Expand All @@ -80,6 +75,7 @@ export const deleteUserById = async (id: string) => {
if (!del) throw new Error("Delete failed");

revalidatePath("/admin/users");
revalidatePath("/", "layout");
return { message: "Berhasil dihapus!", error: false };
} catch (e) {
console.error(e);
Expand Down
2 changes: 2 additions & 0 deletions src/app/(admin)/admin/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export default function RootLayout({
}) {
return <AdminLayout>{children}</AdminLayout>;
}

export const revalidate = 900;
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function OrgGallery({
</div>
</div>
<div className="flex gap-[18px] flex-col lg:flex-row items-center">
<div className="w-full rounded-2xl overflow-hidden h-[280px] sm:h-[310px] md:h-[390px] lg:h-[460px] xl:h-[520px] 2xl:h-[580px]">
<div className="w-full rounded-2xl overflow-hidden h-auto lg:h-[460px] xl:h-[520px] 2xl:h-[580px]">
<Image
src={image}
alt="Image"
Expand Down
11 changes: 2 additions & 9 deletions src/app/(main)/organisasi/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import Maintenance from "@/app/maintenance/page";
import {
findLatestPeriod,
findPeriodWithoutOrganisasi,
} from "@/utils/database/periodYear.query";
import { findLatestPeriod } from "@/utils/database/periodYear.query";
import { redirect } from "next/navigation";

export default async function OrganisasiPage() {
let activePeriod = await findPeriodWithoutOrganisasi({ is_active: true });

if (!activePeriod) {
activePeriod = await findLatestPeriod();
}
const activePeriod = await findLatestPeriod(true);

if (!activePeriod) return <Maintenance />;

Expand Down
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ export default function RootLayout({
</html>
);
}

export const revalidate = 5400;
14 changes: 10 additions & 4 deletions src/utils/database/periodYear.query.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { Period_Year, Prisma } from "@prisma/client";
import { Prisma } from "@prisma/client";

import prisma from "@/lib/prisma";

export const findLatestPeriod = async () => {
const latestPeriodYear = await prisma.period_Year.findMany({});
export const findLatestPeriod = async (isActive?: boolean) => {
let latestPeriodYear = await prisma.period_Year.findMany({});

latestPeriodYear.sort((a, b) => {
return parseInt(b.period.split("/")[0]) - parseInt(a.period.split("/")[0]);
});

return latestPeriodYear[0] as Period_Year;
if (isActive != undefined) {
latestPeriodYear = latestPeriodYear.filter(
(period) => period.is_active == isActive,
);
}

return latestPeriodYear[0];
};

export const findAllPeriod = async (filter?: Prisma.Period_YearWhereInput) => {
Expand Down