From 063e2d8c1184300a9b35af8c67a8fba836b47fe0 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Sun, 4 Feb 2024 20:09:46 -0800 Subject: [PATCH] Use team context in edit. --- .../settings/teams/[teamId]/TeamEditForm.tsx | 20 +++++++------------ src/app/(main)/teams/[teamId]/layout.tsx | 4 ++-- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/app/(main)/settings/teams/[teamId]/TeamEditForm.tsx b/src/app/(main)/settings/teams/[teamId]/TeamEditForm.tsx index d1e80f7b..7e158191 100644 --- a/src/app/(main)/settings/teams/[teamId]/TeamEditForm.tsx +++ b/src/app/(main)/settings/teams/[teamId]/TeamEditForm.tsx @@ -11,27 +11,21 @@ import { useToasts, } from 'react-basics'; import { getRandomChars } from 'next-basics'; -import { useRef, useState } from 'react'; +import { useContext, useRef, useState } from 'react'; import { useApi, useMessages } from 'components/hooks'; +import { TeamContext } from 'app/(main)/teams/[teamId]/TeamProvider'; const generateId = () => getRandomChars(16); -export function TeamEditForm({ - teamId, - data, - allowEdit, -}: { - teamId: string; - data?: { name: string; accessCode: string }; - allowEdit?: boolean; -}) { +export function TeamEditForm({ teamId, allowEdit }: { teamId: string; allowEdit?: boolean }) { + const team = useContext(TeamContext); const { formatMessage, labels, messages } = useMessages(); const { post, useMutation } = useApi(); const { mutate, error } = useMutation({ mutationFn: (data: any) => post(`/teams/${teamId}`, data), }); const ref = useRef(null); - const [accessCode, setAccessCode] = useState(data.accessCode); + const [accessCode, setAccessCode] = useState(team.accessCode); const { showToast } = useToasts(); const handleSubmit = async (data: any) => { @@ -53,7 +47,7 @@ export function TeamEditForm({ }; return ( -
+ @@ -63,7 +57,7 @@ export function TeamEditForm({ )} - {!allowEdit && data.name} + {!allowEdit && team.name} {allowEdit && ( diff --git a/src/app/(main)/teams/[teamId]/layout.tsx b/src/app/(main)/teams/[teamId]/layout.tsx index 24831436..f18d802a 100644 --- a/src/app/(main)/teams/[teamId]/layout.tsx +++ b/src/app/(main)/teams/[teamId]/layout.tsx @@ -1,5 +1,5 @@ import TeamProvider from './TeamProvider'; -export default function ({ children }) { - return {children}; +export default function ({ children, params: { teamId } }) { + return {children}; }