Skip to content

Commit

Permalink
converger logica front-back (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juanito98 authored Oct 29, 2024
1 parent fc6902f commit f9790fe
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions src/pages/registro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,21 @@ import {
} from "@/types/participation.schema";
import { ParticipationRole } from "@prisma/client";
import { X_USER_AUTH_EMAIL_HEADER } from "@/lib/auth";
import { validateOFMIOpenAndCloseTime } from "@/lib/validators/ofmi";
import type { ValidationResult } from "@/lib/validators/types";

export default function RegistroPage({
ofmiEdition,
participationJSON,
registrationClosingTime,
validationResult,
role,
}: InferGetServerSidePropsType<typeof getServerSideProps>): JSX.Element {
if (
ofmiEdition == null ||
(registrationClosingTime && registrationClosingTime < Date.now())
) {
const errorMsg = ofmiEdition ? "El registro de la OFMI ha finalizado." : "";
if (!validationResult.ok) {
return (
<div className="flex w-full items-center justify-center">
<Alert
className="block w-1/2 items-center justify-center"
errorMsg={errorMsg}
errorMsg={validationResult.message}
>
<p>
Si tienes alguna duda por favor envía un correo a &nbsp;
Expand Down Expand Up @@ -63,8 +61,8 @@ export default function RegistroPage({
}

export const getServerSideProps: GetServerSideProps<{
ofmiEdition: number | null;
registrationClosingTime: number | null;
ofmiEdition: number;
validationResult: ValidationResult;
participationJSON: string | null;
role: ParticipationRole;
}> = async ({ req, query }) => {
Expand All @@ -89,20 +87,14 @@ export const getServerSideProps: GetServerSideProps<{
const role =
roleRequested || participation?.userParticipation.role || "CONTESTANT";

const volunteerClosingTime = ofmi?.registrationCloseTime
? new Date(ofmi?.registrationCloseTime.getFullYear(), 12, 31).getTime()
: null;

const closingTime =
role === "VOLUNTEER"
? volunteerClosingTime
: (ofmi?.registrationCloseTime.getTime() ?? null);

return {
props: {
participationJSON: JSON.stringify(participation),
ofmiEdition: ofmi?.edition ?? null,
registrationClosingTime: closingTime,
ofmiEdition: ofmi.edition,
validationResult: validateOFMIOpenAndCloseTime(ofmi, {
registrationTime: new Date(Date.now()),
role,
}),
role,
},
};
Expand Down

0 comments on commit f9790fe

Please sign in to comment.