Commit b9a823da authored by Max Alekseenko's avatar Max Alekseenko

add referrals query

parent fbffec54
import { Button, Flex, Text, useColorModeValue } from '@chakra-ui/react'; import { Button, Flex, Skeleton, Text, useColorModeValue } from '@chakra-ui/react';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import React from 'react'; import React from 'react';
import { useRewardsContext } from 'lib/contexts/rewards'; import { useRewardsContext } from 'lib/contexts/rewards';
import CopyField from 'ui/rewards/CopyField'; import CopyField from 'ui/rewards/CopyField';
import RewardsDashboardCard from 'ui/rewards/RewardsDashboardCard'; import RewardsDashboardCard from 'ui/rewards/RewardsDashboardCard';
import useReferrals from 'ui/rewards/useReferrals';
import IconSvg from 'ui/shared/IconSvg'; import IconSvg from 'ui/shared/IconSvg';
import LinkExternal from 'ui/shared/links/LinkExternal'; import LinkExternal from 'ui/shared/links/LinkExternal';
import PageTitle from 'ui/shared/Page/PageTitle'; import PageTitle from 'ui/shared/Page/PageTitle';
...@@ -12,6 +13,7 @@ import PageTitle from 'ui/shared/Page/PageTitle'; ...@@ -12,6 +13,7 @@ import PageTitle from 'ui/shared/Page/PageTitle';
const RewardsDashboard = () => { const RewardsDashboard = () => {
const router = useRouter(); const router = useRouter();
const { balances, dailyReward, isLogedIn } = useRewardsContext(); const { balances, dailyReward, isLogedIn } = useRewardsContext();
const referralsQuery = useReferrals();
if (!isLogedIn) { if (!isLogedIn) {
router.replace({ pathname: '/' }, undefined, { shallow: true }); router.replace({ pathname: '/' }, undefined, { shallow: true });
...@@ -76,8 +78,8 @@ const RewardsDashboard = () => { ...@@ -76,8 +78,8 @@ const RewardsDashboard = () => {
px={ 6 } px={ 6 }
flexShrink={ 0 } flexShrink={ 0 }
> >
<CopyField label="Referral link" value="blockscout.com/ref/0x789a9201d10029139101"/> <CopyField label="Referral link" value={ referralsQuery.data?.link || '' } isLoading={ referralsQuery.isLoading }/>
<CopyField label="Referral code" value="CODE10"/> <CopyField label="Referral code" value={ referralsQuery.data?.code || '' } isLoading={ referralsQuery.isLoading }/>
<Flex flexDirection="column"> <Flex flexDirection="column">
<Flex alignItems="center" gap={ 1 } w="120px"> <Flex alignItems="center" gap={ 1 } w="120px">
<IconSvg name="info" boxSize={ 5 } color="gray.500"/> <IconSvg name="info" boxSize={ 5 } color="gray.500"/>
...@@ -85,9 +87,11 @@ const RewardsDashboard = () => { ...@@ -85,9 +87,11 @@ const RewardsDashboard = () => {
Referrals Referrals
</Text> </Text>
</Flex> </Flex>
<Text fontSize="32px" fontWeight="500"> <Skeleton isLoaded={ !referralsQuery.isLoading }>
0 <Text fontSize="32px" fontWeight="500">
</Text> { referralsQuery.data?.referrals || 0 }
</Text>
</Skeleton>
</Flex> </Flex>
</Flex> </Flex>
</Flex> </Flex>
......
import { FormControl, Input, InputGroup, InputRightElement, chakra, useColorModeValue } from '@chakra-ui/react'; import { FormControl, Input, InputGroup, InputRightElement, Skeleton, chakra, useColorModeValue } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import CopyToClipboard from 'ui/shared/CopyToClipboard'; import CopyToClipboard from 'ui/shared/CopyToClipboard';
...@@ -8,29 +8,32 @@ type Props = { ...@@ -8,29 +8,32 @@ type Props = {
label: string; label: string;
value: string; value: string;
className?: string; className?: string;
isLoading?: boolean;
}; };
const CopyField = ({ label, value, className }: Props) => { const CopyField = ({ label, value, className, isLoading }: Props) => {
const bgColor = ` ${ useColorModeValue('gray.200', 'blackAlpha.900') } !important`; const bgColor = ` ${ useColorModeValue('gray.200', 'blackAlpha.900') } !important`;
return ( return (
<FormControl variant="floating" id={ label } className={ className }> <FormControl variant="floating" id={ label } className={ className }>
<InputGroup> <Skeleton isLoaded={ !isLoading }>
<Input <InputGroup>
readOnly <Input
fontWeight="500" readOnly
value={ value } fontWeight="500"
overflow="hidden" value={ value }
textOverflow="ellipsis" overflow="hidden"
pr="40px !important" textOverflow="ellipsis"
bgColor={ bgColor } pr="40px !important"
borderColor={ bgColor } bgColor={ bgColor }
borderRadius="12px !important" borderColor={ bgColor }
/> borderRadius="12px !important"
<InputPlaceholder text={ label } bgColor={ bgColor }/> />
<InputRightElement w="40px" display="flex" justifyContent="flex-end" pr={ 2 }> <InputPlaceholder text={ label } bgColor={ bgColor }/>
<CopyToClipboard text={ value }/> <InputRightElement w="40px" display="flex" justifyContent="flex-end" pr={ 2 }>
</InputRightElement> <CopyToClipboard text={ value }/>
</InputGroup> </InputRightElement>
</InputGroup>
</Skeleton>
</FormControl> </FormControl>
); );
}; };
......
...@@ -7,8 +7,10 @@ import IconSvg from 'ui/shared/IconSvg'; ...@@ -7,8 +7,10 @@ import IconSvg from 'ui/shared/IconSvg';
import AvailableSoonLabel from '../AvailableSoonLabel'; import AvailableSoonLabel from '../AvailableSoonLabel';
import CopyField from '../CopyField'; import CopyField from '../CopyField';
import useReferrals from '../useReferrals';
const CongratsStepContent = () => { const CongratsStepContent = () => {
const referralsQuery = useReferrals();
return ( return (
<> <>
<Flex <Flex
...@@ -53,8 +55,13 @@ const CongratsStepContent = () => { ...@@ -53,8 +55,13 @@ const CongratsStepContent = () => {
<Text fontSize="md" mt={ 2 }> <Text fontSize="md" mt={ 2 }>
Receive a 10% bonus on all merits earned by your referrals Receive a 10% bonus on all merits earned by your referrals
</Text> </Text>
<CopyField label="Code" value="Test value" mt={ 3 }/> <CopyField
<Button mt={ 6 }> label="Referral link"
value={ referralsQuery.data?.link || '' }
isLoading={ referralsQuery.isLoading }
mt={ 3 }
/>
<Button mt={ 6 } isLoading={ referralsQuery.isLoading }>
Share on <IconSvg name="social/twitter" boxSize={ 6 } ml={ 1 }/> Share on <IconSvg name="social/twitter" boxSize={ 6 } ml={ 1 }/>
</Button> </Button>
</Flex> </Flex>
......
import config from 'configs/app';
import useApiQuery from 'lib/api/useApiQuery';
import * as cookies from 'lib/cookies';
export default function useReferrals() {
const apiToken = cookies.get(cookies.NAMES.REWARDS_API_TOKEN);
return useApiQuery('rewards_user_referrals', {
queryOptions: {
enabled: Boolean(apiToken) && config.features.rewards.isEnabled,
},
fetchParams: {
headers: {
Authorization: `Bearer ${ apiToken }`,
},
},
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment