chore(trading): create and update team form traversing (#5764)
This commit is contained in:
parent
76c07992d3
commit
5ddcb613e2
@ -1,5 +1,10 @@
|
|||||||
import { useSearchParams } from 'react-router-dom';
|
import { Link, useSearchParams } from 'react-router-dom';
|
||||||
import { Intent, TradingAnchorButton } from '@vegaprotocol/ui-toolkit';
|
import {
|
||||||
|
Intent,
|
||||||
|
TradingAnchorButton,
|
||||||
|
VegaIcon,
|
||||||
|
VegaIconNames,
|
||||||
|
} from '@vegaprotocol/ui-toolkit';
|
||||||
import { useVegaWallet, useVegaWalletDialogStore } from '@vegaprotocol/wallet';
|
import { useVegaWallet, useVegaWalletDialogStore } from '@vegaprotocol/wallet';
|
||||||
import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
|
import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
|
||||||
import { useT } from '../../lib/use-t';
|
import { useT } from '../../lib/use-t';
|
||||||
@ -30,6 +35,19 @@ export const CompetitionsCreateTeam = () => {
|
|||||||
<LayoutWithGradient>
|
<LayoutWithGradient>
|
||||||
<div className="mx-auto md:w-2/3 max-w-xl">
|
<div className="mx-auto md:w-2/3 max-w-xl">
|
||||||
<Box className="flex flex-col gap-4">
|
<Box className="flex flex-col gap-4">
|
||||||
|
<Link
|
||||||
|
to={Links.COMPETITIONS()}
|
||||||
|
className="text-xs inline-flex items-center gap-1 group"
|
||||||
|
>
|
||||||
|
<VegaIcon
|
||||||
|
name={VegaIconNames.CHEVRON_LEFT}
|
||||||
|
size={12}
|
||||||
|
className="text-vega-clight-100 dark:text-vega-cdark-100"
|
||||||
|
/>{' '}
|
||||||
|
<span className="group-hover:underline">
|
||||||
|
{t('Go back to the competitions')}
|
||||||
|
</span>
|
||||||
|
</Link>
|
||||||
<h1 className="calt text-2xl lg:text-3xl xl:text-4xl">
|
<h1 className="calt text-2xl lg:text-3xl xl:text-4xl">
|
||||||
{isSolo ? t('Create solo team') : t('Create a team')}
|
{isSolo ? t('Create solo team') : t('Create a team')}
|
||||||
</h1>
|
</h1>
|
||||||
@ -78,15 +96,17 @@ const CreateTeamFormContainer = ({ isSolo }: { isSolo: boolean }) => {
|
|||||||
<p className="text-sm">{t('Team creation transaction successful')}</p>
|
<p className="text-sm">{t('Team creation transaction successful')}</p>
|
||||||
{code && (
|
{code && (
|
||||||
<>
|
<>
|
||||||
<p className="text-sm">
|
<dl>
|
||||||
Your team ID is:{' '}
|
<dt className="text-sm">{t('Your team ID:')}</dt>
|
||||||
<span
|
<dl>
|
||||||
className="font-mono break-all"
|
<span
|
||||||
data-testid="team-id-display"
|
className="font-mono break-all bg-rainbow bg-clip-text text-transparent text-2xl"
|
||||||
>
|
data-testid="team-id-display"
|
||||||
{code}
|
>
|
||||||
</span>
|
{code}
|
||||||
</p>
|
</span>
|
||||||
|
</dl>
|
||||||
|
</dl>
|
||||||
<TradingAnchorButton
|
<TradingAnchorButton
|
||||||
href={Links.COMPETITIONS_TEAM(code)}
|
href={Links.COMPETITIONS_TEAM(code)}
|
||||||
intent={Intent.Info}
|
intent={Intent.Info}
|
||||||
|
@ -3,7 +3,14 @@ import { usePageTitle } from '../../lib/hooks/use-page-title';
|
|||||||
import { Box } from '../../components/competitions/box';
|
import { Box } from '../../components/competitions/box';
|
||||||
import { useT } from '../../lib/use-t';
|
import { useT } from '../../lib/use-t';
|
||||||
import { useVegaWallet, useVegaWalletDialogStore } from '@vegaprotocol/wallet';
|
import { useVegaWallet, useVegaWalletDialogStore } from '@vegaprotocol/wallet';
|
||||||
import { Loader, Splash } from '@vegaprotocol/ui-toolkit';
|
import {
|
||||||
|
Intent,
|
||||||
|
Loader,
|
||||||
|
Splash,
|
||||||
|
TradingAnchorButton,
|
||||||
|
VegaIcon,
|
||||||
|
VegaIconNames,
|
||||||
|
} from '@vegaprotocol/ui-toolkit';
|
||||||
import { RainbowButton } from '../../components/rainbow-button';
|
import { RainbowButton } from '../../components/rainbow-button';
|
||||||
import { Link, Navigate, useParams } from 'react-router-dom';
|
import { Link, Navigate, useParams } from 'react-router-dom';
|
||||||
import { Links } from '../../lib/links';
|
import { Links } from '../../lib/links';
|
||||||
@ -11,6 +18,7 @@ import { useReferralSetTransaction } from '../../lib/hooks/use-referral-set-tran
|
|||||||
import { type FormFields, TeamForm, TransactionType } from './team-form';
|
import { type FormFields, TeamForm, TransactionType } from './team-form';
|
||||||
import { useTeam } from '../../lib/hooks/use-team';
|
import { useTeam } from '../../lib/hooks/use-team';
|
||||||
import { LayoutWithGradient } from '../../components/layouts-inner';
|
import { LayoutWithGradient } from '../../components/layouts-inner';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
export const CompetitionsUpdateTeam = () => {
|
export const CompetitionsUpdateTeam = () => {
|
||||||
const t = useT();
|
const t = useT();
|
||||||
@ -29,6 +37,19 @@ export const CompetitionsUpdateTeam = () => {
|
|||||||
<LayoutWithGradient>
|
<LayoutWithGradient>
|
||||||
<div className="mx-auto md:w-2/3 max-w-xl">
|
<div className="mx-auto md:w-2/3 max-w-xl">
|
||||||
<Box className="flex flex-col gap-4">
|
<Box className="flex flex-col gap-4">
|
||||||
|
<Link
|
||||||
|
to={Links.COMPETITIONS_TEAM(teamId)}
|
||||||
|
className="text-xs inline-flex items-center gap-1 group"
|
||||||
|
>
|
||||||
|
<VegaIcon
|
||||||
|
name={VegaIconNames.CHEVRON_LEFT}
|
||||||
|
size={12}
|
||||||
|
className="text-vega-clight-100 dark:text-vega-cdark-100"
|
||||||
|
/>{' '}
|
||||||
|
<span className="group-hover:underline">
|
||||||
|
{t('Go back to the team profile')}
|
||||||
|
</span>
|
||||||
|
</Link>
|
||||||
<h1 className="calt text-2xl lg:text-3xl xl:text-5xl">
|
<h1 className="calt text-2xl lg:text-3xl xl:text-5xl">
|
||||||
{t('Update a team')}
|
{t('Update a team')}
|
||||||
</h1>
|
</h1>
|
||||||
@ -57,7 +78,8 @@ const UpdateTeamFormContainer = ({
|
|||||||
pubKey: string;
|
pubKey: string;
|
||||||
}) => {
|
}) => {
|
||||||
const t = useT();
|
const t = useT();
|
||||||
const { team, loading, error } = useTeam(teamId, pubKey);
|
const [refetching, setRefetching] = useState<boolean>(false);
|
||||||
|
const { team, loading, error, refetch } = useTeam(teamId, pubKey);
|
||||||
|
|
||||||
const { err, status, onSubmit } = useReferralSetTransaction({
|
const { err, status, onSubmit } = useReferralSetTransaction({
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
@ -65,7 +87,15 @@ const UpdateTeamFormContainer = ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (loading) {
|
// refetch when saved
|
||||||
|
useEffect(() => {
|
||||||
|
if (refetch && status === 'confirmed') {
|
||||||
|
refetch();
|
||||||
|
setRefetching(true);
|
||||||
|
}
|
||||||
|
}, [refetch, status]);
|
||||||
|
|
||||||
|
if (loading && !refetching) {
|
||||||
return <Loader size="small" />;
|
return <Loader size="small" />;
|
||||||
}
|
}
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -84,6 +114,33 @@ const UpdateTeamFormContainer = ({
|
|||||||
return <Navigate to={Links.COMPETITIONS_TEAM(teamId)} />;
|
return <Navigate to={Links.COMPETITIONS_TEAM(teamId)} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (status === 'confirmed') {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="flex flex-col items-start gap-2"
|
||||||
|
data-testid="team-creation-success-message"
|
||||||
|
>
|
||||||
|
<p className="text-sm">
|
||||||
|
<VegaIcon
|
||||||
|
name={VegaIconNames.TICK}
|
||||||
|
size={18}
|
||||||
|
className="text-vega-green-500"
|
||||||
|
/>{' '}
|
||||||
|
{t('Changes successfully saved to your team.')}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<TradingAnchorButton
|
||||||
|
href={Links.COMPETITIONS_TEAM(teamId)}
|
||||||
|
intent={Intent.Info}
|
||||||
|
size="small"
|
||||||
|
data-testid="view-team-button"
|
||||||
|
>
|
||||||
|
{t('View team')}
|
||||||
|
</TradingAnchorButton>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const defaultValues: FormFields = {
|
const defaultValues: FormFields = {
|
||||||
id: team.teamId,
|
id: team.teamId,
|
||||||
name: team.name,
|
name: team.name,
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
import { isValidUrl } from '@vegaprotocol/utils';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
const NUM_AVATARS = 20;
|
const NUM_AVATARS = 20;
|
||||||
const AVATAR_PATHNAME_PATTERN = '/team-avatars/{id}.png';
|
const AVATAR_PATHNAME_PATTERN = '/team-avatars/{id}.png';
|
||||||
@ -11,6 +13,26 @@ export const getFallbackAvatar = (teamId: string) => {
|
|||||||
return AVATAR_PATHNAME_PATTERN.replace('{id}', avatarId);
|
return AVATAR_PATHNAME_PATTERN.replace('{id}', avatarId);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const useAvatar = (teamId: string, url: string) => {
|
||||||
|
const fallback = getFallbackAvatar(teamId);
|
||||||
|
const [avatar, setAvatar] = useState<string>(fallback);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isValidUrl(url)) return;
|
||||||
|
fetch(url, { cache: 'force-cache' })
|
||||||
|
.then((response) => {
|
||||||
|
if (response.ok) {
|
||||||
|
setAvatar(url);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
/** noop */
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return avatar;
|
||||||
|
};
|
||||||
|
|
||||||
export const TeamAvatar = ({
|
export const TeamAvatar = ({
|
||||||
teamId,
|
teamId,
|
||||||
imgUrl,
|
imgUrl,
|
||||||
@ -22,7 +44,7 @@ export const TeamAvatar = ({
|
|||||||
alt?: string;
|
alt?: string;
|
||||||
size?: 'large' | 'small';
|
size?: 'large' | 'small';
|
||||||
}) => {
|
}) => {
|
||||||
const img = imgUrl && imgUrl.length > 0 ? imgUrl : getFallbackAvatar(teamId);
|
const img = useAvatar(teamId, imgUrl);
|
||||||
return (
|
return (
|
||||||
// eslint-disable-next-line @next/next/no-img-element
|
// eslint-disable-next-line @next/next/no-img-element
|
||||||
<img
|
<img
|
||||||
|
@ -446,5 +446,9 @@
|
|||||||
"Choose a team": "Choose a team",
|
"Choose a team": "Choose a team",
|
||||||
"Join a team": "Join a team",
|
"Join a team": "Join a team",
|
||||||
"Solo team / lone wolf": "Solo team / lone wolf",
|
"Solo team / lone wolf": "Solo team / lone wolf",
|
||||||
"Choose a team to get involved": "Choose a team to get involved"
|
"Choose a team to get involved": "Choose a team to get involved",
|
||||||
|
"Go back to the team's profile": "Go back to the team's profile",
|
||||||
|
"Go back to the competitions": "Go back to the competitions",
|
||||||
|
"Your team ID:": "Your team ID:",
|
||||||
|
"Changes successfully saved to your team.": "Changes successfully saved to your team."
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user