Skip to content

Commit

Permalink
Merge pull request #241 from piyushyadav1617/dev-branch
Browse files Browse the repository at this point in the history
Added referral page
  • Loading branch information
moonlightnexus authored Nov 13, 2023
2 parents 6eed4e3 + db85a45 commit 836e520
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 8 deletions.
185 changes: 185 additions & 0 deletions src/app/dashboard/(pages)/referal/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
'use client';
import React from 'react';
import { Input } from '@/components/ui/Input';
import { Button } from '@/components/ui/Button';
import { useState, useEffect } from 'react';
import { CheckSquareValid } from '@/assets/Svg/Account/Account';
import { ClipboardCopy } from 'lucide-react';
import { useAuth } from '@/Providers/AuthContext';
import { useToast } from '@/components/ui/use-toast';
import { PasswordDialogue } from '@/app/dashboard/components/PasswordDialgue';

import { Dialog, DialogTrigger } from '@/components/ui/Dialog';

function InputWithButtons({ referralLink }: { referralLink: string }) {
const handleCopy = () => {
navigator.clipboard.writeText(referralLink);
};
// referralLink = "edwedwedewqdeded"

const [show, setShow] = useState(false);
console.log(referralLink);
return (
<div className="flex justify-center flex-wrap w-full items-center space-x-2 tracking-wide">
<Input
type={show ? 'text' : 'password'}
value={referralLink}
className="bg-transparent appearance-none border-2 border-gray-200 rounded max-w-[80%] sm:max-w-[65%] w-full min-w-fit py-2 px-3 text-black leading-tight focus:outline-none focus:border-black"
/>
<div className="flex justify-center items-center gap-2">
<Button
variant={'authx'}
className="w-20"
type="button"
onClick={() => setShow(!show)}
>
{show ? 'Hide' : 'Reveal'}
</Button>
<Button variant={'authx'} type="button" onClick={handleCopy}>
<ClipboardCopy size={18} />

<span className="ml-2">Copy</span>
</Button>
</div>
</div>
);
}

export default function Referral() {
const { token } = useAuth();
const { toast } = useToast();
const [generated, setGenerated] = useState(false);
const [referralLink, setReferralLink] = useState('');

const [loading, setLoading] = useState(false);
const [total, setTotal] = useState('');
useEffect(() => {
getReferralCount();
}, []);
async function generateKeys() {
setLoading(true);
try {
const response = await fetch(`https://api.trustauthx.com/ref/link`, {
method: 'GET',
headers: {
accept: 'application/json',
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json'
}
});

if (response.status === 200) {
let { url } = (await response.json()) as { url: string };
console.log(url);
url = String(url);
setReferralLink(url);
setGenerated(true);
setLoading(false);
return;
}
} catch (error: any) {
toast({
variant: 'destructive',
title: 'Uh oh! Something went wrong with your request',
description: error.message
});
setLoading(false);
return;
}
}
async function getReferralCount() {
try {
{
const response = await fetch(`https://api.trustauthx.com/ref/stat`, {
method: 'GET',
headers: {
accept: 'application/json',
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json'
}
});

const { total } = (await response.json()) as { total: string };
setTotal(total);

return;
}
} catch (error: any) {
toast({
variant: 'destructive',
title: 'Uh oh! Something went wrong with your request',
description: error.message
});
return;
}
}

return (
<>
{generated ? (
<div className="flex flex-col gap-8 max-w-3xl mt-14 p-14 border border-slate-300 text-[#2E2E2E] rounded-lg">
<div>
<h2 className="text-2xl font-semibold tracking-wide mb-6 ml-4">
This is your referral Link
</h2>
</div>
<div>
<InputWithButtons referralLink={referralLink} />
</div>

<Button
className="mx-auto max-w-[90%]"
variant={'authx'}
type="button"
onClick={() => {
setGenerated(false);
}}
>
<CheckSquareValid />
<span className="p-2 ">I’ve copied the Link</span>
</Button>
</div>
) : (
<div className="flex flex-col">
<div className="flex flex-col gap-8 max-w-3xl mt-14 p-14 border border-slate-300 text-[#2E2E2E] rounded-lg ">
<div>
<h2 className="text-3xl font-semibold tracking-wide mb-6">
Create Your Referral Link
</h2>
<p className="text-lg font-extralight tracking-wide">
<span className="font-semibold">*Referral</span> : The Referral
program is governed by Trustauthx's Referral policy, by
continuing you agree to our terms.
</p>
</div>

<Dialog>
<DialogTrigger className="py-2 text-sm px-8 bg-accent text-black shadow hover:text-white hover:bg-black min-w-fit w-48 rounded-md flex items-start h-fit ">
+ Create and copy my referal link
</DialogTrigger>
<PasswordDialogue request={generateKeys} loading={loading} />
</Dialog>
</div>
<div className="flex flex-col gap-8 max-w-3xl mt-8 p-14 border border-slate-300 text-[#2E2E2E] rounded-lg ">
<div>
<h2 className="text-3xl font-semibold tracking-wide mb-6">
Your Referral Count
</h2>
<p className="text-lg font-extralight tracking-wide">
<span className="font-semibold">*Note</span> : This number does
not reflect the actual numbers of subscribers.
</p>
</div>

<div className="py-2 flex flex-col items-start h-fit ">
<h3 className=" text-2xl font-semibold">{total} Users</h3>
<span className="text-sm text-slate-400">
Accepted your Referral
</span>
</div>
</div>
</div>
)}
</>
);
}
17 changes: 9 additions & 8 deletions src/app/dashboard/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import React, { useEffect, useState } from 'react';
import {
OrgnaizationSvg,
SupportSvg
SupportSvg,
ReferalSvg
} from '../../../assets/Svg/Account/Account';
import { ChevronsLeft, ChevronsRight, Menu, X } from 'lucide-react';

Expand Down Expand Up @@ -71,7 +72,7 @@ export const Sidebar = () => {
<h3 className=" text-2xl text-bold mb-12">
{open ? 'Organization' : ''}
</h3>
<div className={"main-menu flex flex-col w-full"}>
<div className={'main-menu flex flex-col w-full'}>
<h4 className="text-[0.75rem] opacity-50 ml-8 pl-8">
{open ? 'Main menu' : ''}
</h4>
Expand All @@ -93,7 +94,7 @@ export const Sidebar = () => {
</Link>
</div>
</div>
<div className={"General flex flex-col w-full"}>
<div className={'General flex flex-col w-full'}>
<h4 className="text-[0.75rem] opacity-50 ml-8 pl-8">
{open ? 'General' : ''}
</h4>
Expand All @@ -113,17 +114,17 @@ export const Sidebar = () => {
</span>
{open ? <span>Support</span> : ''}
</Link>
{/* <Link
href={'#'}
<Link
href={'/dashboard/referal'}
className={`hover:bg-white hover:bg-opacity-40 ${
open ? 'ml-8 pl-8 w-3/4 py-2' : 'p-2'
} mb-4 rounded-md flex items-center space-x-2`}
>
<span>
<SettingSvg />
<ReferalSvg />
</span>
{open ? <span>Settings</span> : ''}
</Link> */}
{open ? <span>Referral</span> : ''}
</Link>
</div>
</div>
</div>
Expand Down
23 changes: 23 additions & 0 deletions src/assets/Svg/Account/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,29 @@ export const CopyPasteSvg = () => {
</svg>
);
};
export const ReferalSvg = () => {
return (
<svg
width="23"
height="20"
viewBox="0 0 23 20"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M2.5 5C2.5 5.98891 2.79324 6.9556 3.34265 7.77785C3.89206 8.60009 4.67295 9.24096 5.58658 9.6194C6.50021 9.99783 7.50555 10.0968 8.47545 9.90392C9.44535 9.711 10.3363 9.23479 11.0355 8.53553C11.7348 7.83627 12.211 6.94535 12.4039 5.97545C12.5968 5.00555 12.4978 4.00021 12.1194 3.08658C11.741 2.17295 11.1001 1.39206 10.2778 0.842652C9.4556 0.293245 8.4889 0 7.5 0C6.17392 0 4.90215 0.526784 3.96447 1.46447C3.02678 2.40215 2.5 3.67392 2.5 5V5Z"
fill="#9EFF00"
/>
<rect y="12.5" width="15" height="7.5" rx="3.75" fill="#9EFF00" />
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M20 5H17.5V7.5H15V10H17.5V12.5H20V10H22.5V7.5H20V5Z"
fill="#9EFF00"
/>
</svg>
);
};

export const CheckSquareValid = () => {
return (
Expand Down

0 comments on commit 836e520

Please sign in to comment.