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

Avenmia/fix demographic survey size for mobile #143

Merged
merged 4 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/survey/demographicssurvey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default function DemographicsSurvey() {
);
};
return (
<div className="flex h-screen flex-col items-center justify-center">
<div className="flex h-screen flex-col items-center">
{surveyCompleted ? (
completedSurvey()
) : (
Expand Down
2 changes: 1 addition & 1 deletion src/components/survey/surveyquestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default function SurveyQuestion({
}
};
return (
<div className="mt-8 flex w-[32rem] flex-col rounded-md bg-[#FFFFFF] px-8 py-8 shadow-xl">
<div className="mt-8 flex max-w-[32rem] flex-col rounded-md bg-[#FFFFFF] px-8 py-8 shadow-xl">
<h1 className="mb-8 font-semibold">
{surveyInfo.questionNumber + 1}. {question.question}
</h1>
Expand Down
43 changes: 25 additions & 18 deletions src/pages/api/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import multiparty from "multiparty";
import ObjectsToCsv from "objects-to-csv";
import csv from "csv-parser";
import fs from "fs";
import { authOptions } from './../../server/auth'
import { getServerSession } from "next-auth/next"
import { authOptions } from "./../../server/auth";
import { getServerSession } from "next-auth/next";

import { prisma } from "../../server/db";

Expand All @@ -17,12 +17,17 @@ export const config = {
},
};

export const authorizedEmails = fs.readFileSync(process.env.AUTHORIZED_POLIS_CONVERT_EMAILS_FILE, 'utf8').split(/\r?\n/);
console.log("Emails authorized to export POLIS data: " + authorizedEmails);
export const authorizedEmails = fs
.readFileSync(process.env.AUTHORIZED_POLIS_CONVERT_EMAILS_FILE, "utf8")
.split(/\r?\n/);

function handleError(error, res) {
console.error(error.stack);
res.status(500).end("Sorry, an error occured while processing a Pol.is export. The error has been logged for admistrators.");
res
.status(500)
.end(
"Sorry, an error occured while processing a Pol.is export. The error has been logged for admistrators."
);
}

const handler = nc({
Expand All @@ -31,7 +36,6 @@ const handler = nc({
res.status(404).end("Page is not found");
},
}).post(async (req, res) => {

const sessionData = await getServerSession(req, res, authOptions);

if (!sessionData) {
Expand All @@ -40,7 +44,9 @@ const handler = nc({
}
const email = sessionData.user.email;
if (!authorizedEmails.includes(email)) {
res.status(403).end(email + ", you are not authorized to export Pol.is data.");
res
.status(403)
.end(email + ", you are not authorized to export Pol.is data.");
return;
}

Expand Down Expand Up @@ -92,18 +98,19 @@ const handler = nc({
})
.on("end", function () {
// wait for all promises to be completed
Promise.all(output).then((resolved) => {
// convert all rows back to CSV
// TODO - remove numeral keys from object, so that they are not added as extra columns in export
new ObjectsToCsv(resolved).toString().then((text) => {
// write CSV to output stream
res.setHeader("Content-Type", "text/csv");
res.end(text);
Promise.all(output)
.then((resolved) => {
// convert all rows back to CSV
// TODO - remove numeral keys from object, so that they are not added as extra columns in export
new ObjectsToCsv(resolved).toString().then((text) => {
// write CSV to output stream
res.setHeader("Content-Type", "text/csv");
res.end(text);
});
})
.catch((error) => {
handleError(error, res);
});
})
.catch(error => {
handleError(error, res);
});
});
});
});
Expand Down
1 change: 0 additions & 1 deletion src/pages/loggedinas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ interface LoggedInAsProps {
}

export default function LoggedInAs({ email }: LoggedInAsProps) {
console.log("Email is:", email);
if (!email) {
return null;
}
Expand Down
Loading