Skip to content

Commit

Permalink
Ver mi carpeta Google Drive (#119)
Browse files Browse the repository at this point in the history
* Ver mi carpeta Google Drive

* open in new tab

* Remove logs
  • Loading branch information
Juanito98 authored Jan 26, 2025
1 parent 39b9dba commit 92645cb
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/components/navbar/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ export const ProfileDropdown = (): JSX.Element => {
</a>
)}
</Menu.Item>
<Menu.Item>
{({ active }: { active: boolean }) => (
<a
href="/repository"
className={classNames(
active ? "bg-gray-100" : "",
"block px-4 py-2 text-sm text-gray-700",
)}
target="_blank"
>
Ver mi carpeta
</a>
)}
</Menu.Item>
<Menu.Item>
{({ active }: { active: boolean }) => (
<a
Expand Down
1 change: 1 addition & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const withAuthPaths = [
"/registro",
"/oauth",
"/updateContactData",
"/repository",
"/api/ofmi/upsertParticipation",
"/api/user/updateContactData",
];
Expand Down
65 changes: 65 additions & 0 deletions src/pages/repository.tsx
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,
},
};
};

0 comments on commit 92645cb

Please sign in to comment.