Tweaks and fixes, add code generator

This commit is contained in:
MeowcaTheoRange 2023-09-24 20:38:49 -05:00
parent da4c3d3838
commit 011e71e715
3 changed files with 31 additions and 2 deletions

View file

@ -4,6 +4,7 @@ import globals from "@/styles/global.module.css";
import form_globals from "@/styles/global_form.module.css";
import { Color3 } from "@/types/assist/color";
import { SubmitClan, SubmitClanSchema } from "@/types/client/clan";
import { getCookie } from "cookies-next";
import { ArrayHelpers, ErrorMessage, Field, FieldArray, Form, Formik } from "formik";
import { NextRouter } from "next/router";
import { useState } from "react";
@ -34,7 +35,8 @@ export default function ClanFormTemplate({
name: "",
pronouns: [["", "", ""]]
}
]
],
code: getCookie("TROLLCALL_CODE")
} as SubmitClan)
}
validationSchema={SubmitClanSchema}

View file

@ -0,0 +1,23 @@
import { mainDB } from "@/lib/db/mongodb";
import { hash } from "argon2";
import { NextApiRequest, NextApiResponse } from "next";
export async function addMany(
collection: string,
items: { [key: string]: any }[]
) {
const selectedCollection = mainDB.collection(collection);
return await selectedCollection.insertMany(items, { ordered: true });
}
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const { body, cookies, query, method } = req;
if (method === "GET") {
if (query.code == null) return res.status(400).end();
return res.status(200).send(await hash(query.code.toString()));
} else return res.status(405).end();
}

View file

@ -9,6 +9,7 @@ import { ClientClan } from "@/types/clan";
import { ThemerGetSet } from "@/types/generics";
import AuthContext from "@/utility/react/AuthContext";
import { defaultTheme } from "@/utility/react/Themer";
import { getCookie } from "cookies-next";
import { GetServerSideProps, GetStaticPropsContext } from "next";
import { useRouter } from "next/router";
import { useContext, useEffect, useState } from "react";
@ -38,7 +39,10 @@ export default function AddTroll({
router={router}
method="PUT"
onSubmitURI={`/api/clan/${clan.name}`}
initialValues={ClientClanToSubmitClan(clan)}
initialValues={{
...ClientClanToSubmitClan(clan),
code: getCookie("TROLLCALL_CODE")
}}
/>
</>
) : (