From 73c1a9d6e28f8e51d673b7ceff96cd5618c7dc80 Mon Sep 17 00:00:00 2001 From: ganning127 Date: Sun, 28 Jul 2024 01:28:39 -0400 Subject: [PATCH 1/3] template code for fetching is setup --- src/components/create/form/TeamInfoForm.tsx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/components/create/form/TeamInfoForm.tsx b/src/components/create/form/TeamInfoForm.tsx index a4e43fd..cd7e663 100644 --- a/src/components/create/form/TeamInfoForm.tsx +++ b/src/components/create/form/TeamInfoForm.tsx @@ -6,6 +6,7 @@ import { apiUrl, Service } from "@hex-labs/core"; import { User } from "../../../types/User"; import { FORM_LAYOUT, FORM_RULES, handleAxiosError } from "../../../util/util"; +import useAxios from "axios-hooks"; const { Title, Text } = Typography; @@ -17,6 +18,23 @@ interface Props { } const TeamInfoForm: React.FC = props => { + const [{ data: hexathonsData, loading: hexathonsLoading, error: hexathonsError }] = useAxios( + apiUrl(Service.HEXATHONS, "/hexathons") + ); + + const activeHexathon = hexathonsData?.find((hexathon: any) => hexathon.isActive); // TODO: change to current hexathon context + // TODO: verify that isTeamBased is set to true + + const [{ data: teamsData, loading: teamsLoading, error: teamsError }] = useAxios( + { + url: apiUrl(Service.HEXATHONS, `/teams`), + params: { + hexathon: "647fee51768e521dc8ef88e0", + userId: props.user.id + } + } + ); + const onFinish = async (values: any) => { const hide = message.loading("Loading...", 0); const newValues = { @@ -39,6 +57,8 @@ const TeamInfoForm: React.FC = props => { }); }; + + const onFinishFailed = (errorInfo: any) => { message.error("Please complete the required fields.", 2); }; From 7105bfce20f2c01031f4e01946ab3bedca482412 Mon Sep 17 00:00:00 2001 From: ganning127 Date: Fri, 9 Aug 2024 00:56:04 -0400 Subject: [PATCH 2/3] testing changes --- src/components/create/form/TeamInfoForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/create/form/TeamInfoForm.tsx b/src/components/create/form/TeamInfoForm.tsx index cd7e663..99c4ea7 100644 --- a/src/components/create/form/TeamInfoForm.tsx +++ b/src/components/create/form/TeamInfoForm.tsx @@ -29,7 +29,7 @@ const TeamInfoForm: React.FC = props => { { url: apiUrl(Service.HEXATHONS, `/teams`), params: { - hexathon: "647fee51768e521dc8ef88e0", + hexathon: "6695c14ed8fb7680e9e3955c", userId: props.user.id } } From e038bfb7f3f559e7db3c840c04ecdc5a00282661 Mon Sep 17 00:00:00 2001 From: ganning127 Date: Sun, 25 Aug 2024 23:00:52 -0400 Subject: [PATCH 3/3] added auto-populating teams --- src/components/create/form/TeamInfoForm.tsx | 25 ++++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/components/create/form/TeamInfoForm.tsx b/src/components/create/form/TeamInfoForm.tsx index 99c4ea7..e707a55 100644 --- a/src/components/create/form/TeamInfoForm.tsx +++ b/src/components/create/form/TeamInfoForm.tsx @@ -2,7 +2,7 @@ import React from "react"; import { Form, Row, Col, message, Input, Button, Typography, Alert } from "antd"; import { PlusOutlined, DeleteOutlined } from "@ant-design/icons"; import axios from "axios"; -import { apiUrl, Service } from "@hex-labs/core"; +import { apiUrl, Service, useAuth } from "@hex-labs/core"; import { User } from "../../../types/User"; import { FORM_LAYOUT, FORM_RULES, handleAxiosError } from "../../../util/util"; @@ -18,19 +18,19 @@ interface Props { } const TeamInfoForm: React.FC = props => { + const theUser = useAuth(); const [{ data: hexathonsData, loading: hexathonsLoading, error: hexathonsError }] = useAxios( apiUrl(Service.HEXATHONS, "/hexathons") ); const activeHexathon = hexathonsData?.find((hexathon: any) => hexathon.isActive); // TODO: change to current hexathon context // TODO: verify that isTeamBased is set to true - const [{ data: teamsData, loading: teamsLoading, error: teamsError }] = useAxios( { url: apiUrl(Service.HEXATHONS, `/teams`), params: { - hexathon: "6695c14ed8fb7680e9e3955c", - userId: props.user.id + hexathon: activeHexathon?.id, + userId: (theUser as any)?.user?.uid, } } ); @@ -63,10 +63,23 @@ const TeamInfoForm: React.FC = props => { message.error("Please complete the required fields.", 2); }; - let formInitialValue = {}; + + if (teamsLoading) { + return Loading...; + } + + let formInitialValue: { members?: { email: string }[] } = {}; if (props.data.members) { + console.log("props.data", props.data); formInitialValue = props.data; + } else if (teamsData && teamsData.count > 0) { + const emails = teamsData.teams[0].members.map((member: any) => ({ email: member.email })); + + const first = theUser?.user?.email; + // eslint-disable-next-line no-nested-ternary + emails.sort((a: any, b: any) => (a.email === first ? -1 : b.email === first ? 1 : 0)); + formInitialValue = { members: emails }; } else { formInitialValue = { members: [ @@ -92,7 +105,7 @@ const TeamInfoForm: React.FC = props => { Team Info Please list all the emails of all your team members below. Make sure the emails used are the - ones that they were accepted for through registration. + ones that they were accepted for through registration. Data is auto-populated based on match.hexlabs.org (if available).