-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Ver mi carpeta Google Drive * open in new tab * Remove logs
- Loading branch information
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import type { | ||
GetServerSideProps, | ||
InferGetServerSidePropsType, | ||
} from "next/types"; | ||
import { findOrCreateDriveFolderForParticipant } from "@/lib/admin"; | ||
import { | ||
findMostRecentOfmi, | ||
findParticipation, | ||
friendlyOfmiName, | ||
} from "@/lib/ofmi"; | ||
import { Alert } from "@/components/alert"; | ||
import { X_USER_AUTH_EMAIL_HEADER } from "@/lib/auth"; | ||
|
||
export default function ResourcesPage( | ||
props: InferGetServerSidePropsType<typeof getServerSideProps>, | ||
): JSX.Element { | ||
return ( | ||
<div className="flex w-full items-center justify-center"> | ||
<Alert | ||
className="block w-1/2 items-center justify-center" | ||
errorMsg={props.errorMsg} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export const getServerSideProps: GetServerSideProps<{ | ||
errorMsg: string; | ||
}> = async ({ req }) => { | ||
const email = req.headers[X_USER_AUTH_EMAIL_HEADER]; | ||
if (!email || typeof email !== "string") { | ||
return { | ||
redirect: { | ||
destination: "/login", | ||
permanent: false, | ||
}, | ||
}; | ||
} | ||
|
||
const ofmi = await findMostRecentOfmi(); | ||
const participation = | ||
ofmi && email ? await findParticipation(ofmi, email) : null; | ||
|
||
let errorMsg = ""; | ||
if (participation === null) { | ||
errorMsg = `Asegúrate que estás inscrita a la ${friendlyOfmiName(ofmi.edition)}`; | ||
} else { | ||
const gDriveFolderUrl = await findOrCreateDriveFolderForParticipant({ | ||
email, | ||
ofmiEdition: ofmi.edition, | ||
}); | ||
return { | ||
redirect: { | ||
destination: gDriveFolderUrl, | ||
permanent: false, | ||
}, | ||
}; | ||
} | ||
|
||
return { | ||
props: { | ||
errorMsg, | ||
}, | ||
}; | ||
}; |