mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-01 20:39:44 +01:00
Use team context in edit.
This commit is contained in:
parent
cc273092d5
commit
063e2d8c11
@ -11,27 +11,21 @@ import {
|
|||||||
useToasts,
|
useToasts,
|
||||||
} from 'react-basics';
|
} from 'react-basics';
|
||||||
import { getRandomChars } from 'next-basics';
|
import { getRandomChars } from 'next-basics';
|
||||||
import { useRef, useState } from 'react';
|
import { useContext, useRef, useState } from 'react';
|
||||||
import { useApi, useMessages } from 'components/hooks';
|
import { useApi, useMessages } from 'components/hooks';
|
||||||
|
import { TeamContext } from 'app/(main)/teams/[teamId]/TeamProvider';
|
||||||
|
|
||||||
const generateId = () => getRandomChars(16);
|
const generateId = () => getRandomChars(16);
|
||||||
|
|
||||||
export function TeamEditForm({
|
export function TeamEditForm({ teamId, allowEdit }: { teamId: string; allowEdit?: boolean }) {
|
||||||
teamId,
|
const team = useContext(TeamContext);
|
||||||
data,
|
|
||||||
allowEdit,
|
|
||||||
}: {
|
|
||||||
teamId: string;
|
|
||||||
data?: { name: string; accessCode: string };
|
|
||||||
allowEdit?: boolean;
|
|
||||||
}) {
|
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
const { mutate, error } = useMutation({
|
const { mutate, error } = useMutation({
|
||||||
mutationFn: (data: any) => post(`/teams/${teamId}`, data),
|
mutationFn: (data: any) => post(`/teams/${teamId}`, data),
|
||||||
});
|
});
|
||||||
const ref = useRef(null);
|
const ref = useRef(null);
|
||||||
const [accessCode, setAccessCode] = useState(data.accessCode);
|
const [accessCode, setAccessCode] = useState(team.accessCode);
|
||||||
const { showToast } = useToasts();
|
const { showToast } = useToasts();
|
||||||
|
|
||||||
const handleSubmit = async (data: any) => {
|
const handleSubmit = async (data: any) => {
|
||||||
@ -53,7 +47,7 @@ export function TeamEditForm({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form ref={ref} onSubmit={handleSubmit} error={error} values={data}>
|
<Form ref={ref} onSubmit={handleSubmit} error={error} values={team}>
|
||||||
<FormRow label={formatMessage(labels.teamId)}>
|
<FormRow label={formatMessage(labels.teamId)}>
|
||||||
<TextField value={teamId} readOnly allowCopy />
|
<TextField value={teamId} readOnly allowCopy />
|
||||||
</FormRow>
|
</FormRow>
|
||||||
@ -63,7 +57,7 @@ export function TeamEditForm({
|
|||||||
<TextField />
|
<TextField />
|
||||||
</FormInput>
|
</FormInput>
|
||||||
)}
|
)}
|
||||||
{!allowEdit && data.name}
|
{!allowEdit && team.name}
|
||||||
</FormRow>
|
</FormRow>
|
||||||
{allowEdit && (
|
{allowEdit && (
|
||||||
<FormRow label={formatMessage(labels.accessCode)}>
|
<FormRow label={formatMessage(labels.accessCode)}>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import TeamProvider from './TeamProvider';
|
import TeamProvider from './TeamProvider';
|
||||||
|
|
||||||
export default function ({ children }) {
|
export default function ({ children, params: { teamId } }) {
|
||||||
return <TeamProvider>{children}</TeamProvider>;
|
return <TeamProvider teamId={teamId}>{children}</TeamProvider>;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user