email confirm template, fix admin login, try fix translation error logs

This commit is contained in:
Dobromir Popov
2024-04-30 13:18:38 +03:00
parent 5135a95db7
commit f303ae193c
5 changed files with 106 additions and 43 deletions

View File

@ -1,5 +1,6 @@
import axiosServer from '../../../../src/axiosServer';
import NewPubPage from "../new";
const common = require('../../../../src/helpers/common');
export default NewPubPage;
import { Assignment, Shift, UserRole, AvailabilityType } from "prisma/prisma-client";
@ -40,6 +41,8 @@ function getShiftGroups(shifts: [Shift]) {
export const getServerSideProps = async (context) => {
const axios = await axiosServer(context);
const prisma = common.getPrismaClient();
// const isAdmin = await ProtectedRoute.IsInRole(UserRole.ADMIN); does not work on server side
context.res.setHeader("Cache-Control", "s-maxage=1, stale-while-revalidate");
if (!context.query || !context.query.id) {
@ -47,13 +50,20 @@ export const getServerSideProps = async (context) => {
props: {}
};
}
var url = process.env.NEXT_PUBLIC_PUBLIC_URL + "/api/data/publishers/" + context.query.id + "?include=availabilities,assignments,assignments.shift";
console.log("GET PUBLISHER FROM:" + url)
try {
const { data: item } = await axios.get(url);
} catch (error) {
console.log("error fetching publisher: " + error);
//redirect to message page with message "no account found". get user from session
const item = await prisma.publisher.findUnique({
where: {
id: context.query.id
},
include: {
availabilities: true,
assignments: {
include: {
shift: true
}
}
}
});
if (!item) {
const user = context.req.session.user;
return {
redirect: {
@ -62,7 +72,6 @@ export const getServerSideProps = async (context) => {
},
}
}
// item.allShifts = item.assignments.map((a: Assignment[]) => a.shift);
// ============================================================
@ -113,7 +122,7 @@ export const getServerSideProps = async (context) => {
// console.dir(item, { depth: null });
return {
props: {
item: item
item: common.convertDatesToISOStrings(item),
},
};
};