From 4ef878514714f21d0d75d638156b4cc4a034ca58 Mon Sep 17 00:00:00 2001 From: timwekkenbc Date: Mon, 22 Apr 2024 10:23:37 -0700 Subject: [PATCH] Updated submissions editing and fetching to account for changes to chefsFormAPIKey (allows submissions for each rule to be supported properly), Removed unneeded library, Switched home page to use client component to hopefully fix loading issue --- app/admin/page.tsx | 9 ++++- .../SubmissionSelector/SubmissionSelector.tsx | 2 +- app/page.tsx | 36 +++++++++++++++---- app/types/ruleInfo.d.ts | 1 + app/utils/api.ts | 4 +-- package-lock.json | 11 ------ package.json | 1 - 7 files changed, 41 insertions(+), 23 deletions(-) diff --git a/app/admin/page.tsx b/app/admin/page.tsx index 68d6d3e..db2371e 100644 --- a/app/admin/page.tsx +++ b/app/admin/page.tsx @@ -35,6 +35,7 @@ export default function Admin() { title: "", goRulesJSONFilename: "", chefsFormId: "", + chefsFormAPIKey: "", }); setRules(newRules); }; @@ -62,7 +63,8 @@ export default function Admin() { initialRule._id !== rule._id || initialRule.title !== rule.title || initialRule.goRulesJSONFilename !== rule.goRulesJSONFilename || - initialRule.chefsFormId !== rule.chefsFormId + initialRule.chefsFormId !== rule.chefsFormId || + initialRule.chefsFormAPIKey !== rule.chefsFormAPIKey ) { return { rule, action: ACTION_STATUS.UPDATE }; } @@ -127,6 +129,11 @@ export default function Admin() { dataIndex: "chefsFormId", render: renderInputField("chefsFormId"), }, + { + title: "CHEFS Form API Key", + dataIndex: "chefsFormAPIKey", + render: renderInputField("chefsFormAPIKey"), + }, { dataIndex: "delete", render: (value: string, _: RuleInfo, index: number) => ( diff --git a/app/components/SubmissionSelector/SubmissionSelector.tsx b/app/components/SubmissionSelector/SubmissionSelector.tsx index 64fa7d9..c7b8744 100644 --- a/app/components/SubmissionSelector/SubmissionSelector.tsx +++ b/app/components/SubmissionSelector/SubmissionSelector.tsx @@ -20,7 +20,7 @@ export default function SubmissionSelector({ chefsFormId, setSelectedSubmissionI submission: { submission: { data }, }, - } = await getSubmissionFromCHEFSById(valueToIdMap[value]); + } = await getSubmissionFromCHEFSById(chefsFormId, valueToIdMap[value]); setSelectedSubmissionInputs(data); }; diff --git a/app/page.tsx b/app/page.tsx index b8cff2f..7a58144 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,17 +1,33 @@ -import { Table, Button, Flex } from "antd"; +"use client"; +import { useState, useEffect } from "react"; import Link from "next/link"; +import { Button, Flex, Spin, Table } from "antd"; import { RuleInfo } from "./types/ruleInfo"; import { getAllRuleData } from "./utils/api"; -export default async function Home() { - const rules: RuleInfo[] = await getAllRuleData(); +export default function Home() { + const [rules, setRules] = useState([]); + const [isLoading, setIsLoading] = useState(true); - const mappedRules = rules.map(({ _id, title, chefsFormId }, key) => { + useEffect(() => { + const getRules = async () => { + try { + const ruleData = await getAllRuleData(); + setRules(ruleData); + setIsLoading(false); + } catch (error) { + console.error(`Error loading rules: ${error}`); + } + }; + getRules(); + }, []); + + const mappedRules = rules.map(({ _id, title, chefsFormId }) => { return { - key, + key: _id, titleLink: ( - {title} + {title} ), editRule: ( @@ -46,7 +62,13 @@ export default async function Home() { - + {isLoading ? ( + +
+ + ) : ( +
+ )} ); } diff --git a/app/types/ruleInfo.d.ts b/app/types/ruleInfo.d.ts index 0990872..7c5daf3 100644 --- a/app/types/ruleInfo.d.ts +++ b/app/types/ruleInfo.d.ts @@ -3,4 +3,5 @@ export interface RuleInfo { title: string; goRulesJSONFilename: string; chefsFormId: string; + chefsFormAPIKey?: string; } diff --git a/app/utils/api.ts b/app/utils/api.ts index f569427..59bed70 100644 --- a/app/utils/api.ts +++ b/app/utils/api.ts @@ -73,9 +73,9 @@ export const getSubmissionsFromCHEFS = async (formId: string) => { * @returns The submissions data. * @throws If an error occurs while fetching the submissions. */ -export const getSubmissionFromCHEFSById = async (id: string) => { +export const getSubmissionFromCHEFSById = async (formId: string, id: string) => { try { - const { data } = await axios.get(`${process.env.NEXT_PUBLIC_API_URL}/submissions/${id}`); + const { data } = await axios.get(`${process.env.NEXT_PUBLIC_API_URL}/submissions/${formId}/${id}`); return data; } catch (error) { console.error(`Error fetching submissions: ${error}`); diff --git a/package-lock.json b/package-lock.json index 2bd236c..6311dc9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,6 @@ "react-dom": "^18" }, "devDependencies": { - "@types/antd": "^1.0.0", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", @@ -1324,16 +1323,6 @@ "url": "https://github.com/sponsors/tannerlinsley" } }, - "node_modules/@types/antd": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@types/antd/-/antd-1.0.0.tgz", - "integrity": "sha512-wnRh+S6vPMahsuSN6lFJQzNXuhUKr9JKic1L/NMdIChsuu9Fc+mDyF7H17eFPQlgpLVdT0DyYIgB1di8DA9AuQ==", - "deprecated": "This is a stub types definition for antd (https://github.com/ant-design/ant-design). antd provides its own type definitions, so you don't need @types/antd installed!", - "dev": true, - "dependencies": { - "antd": "*" - } - }, "node_modules/@types/base16": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/@types/base16/-/base16-1.0.5.tgz", diff --git a/package.json b/package.json index 3c0f84d..864ccca 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ "react-dom": "^18" }, "devDependencies": { - "@types/antd": "^1.0.0", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18",