From 36117dffe8a4753e73efa2f2d9a0867663decbdd Mon Sep 17 00:00:00 2001 From: piyush yadav Date: Tue, 14 Nov 2023 00:34:33 +0530 Subject: [PATCH] added referral page --- src/app/dashboard/(pages)/referal/page.tsx | 185 +++++++++++++++++++++ src/app/dashboard/components/Sidebar.tsx | 17 +- src/assets/Svg/Account/Account.tsx | 23 +++ 3 files changed, 217 insertions(+), 8 deletions(-) create mode 100644 src/app/dashboard/(pages)/referal/page.tsx diff --git a/src/app/dashboard/(pages)/referal/page.tsx b/src/app/dashboard/(pages)/referal/page.tsx new file mode 100644 index 00000000..3442cbc9 --- /dev/null +++ b/src/app/dashboard/(pages)/referal/page.tsx @@ -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 ( +
+ +
+ + +
+
+ ); +} + +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 ? ( +
+
+

+ This is your referral Link +

+
+
+ +
+ + +
+ ) : ( +
+
+
+

+ Create Your Referral Link +

+

+ *Referral : The Referral + program is governed by Trustauthx's Referral policy, by + continuing you agree to our terms. +

+
+ + + + + Create and copy my referal link + + + +
+
+
+

+ Your Referral Count +

+

+ *Note : This number does + not reflect the actual numbers of subscribers. +

+
+ +
+

{total} Users

+ + Accepted your Referral + +
+
+
+ )} + + ); +} diff --git a/src/app/dashboard/components/Sidebar.tsx b/src/app/dashboard/components/Sidebar.tsx index 8b494bf4..b1875223 100644 --- a/src/app/dashboard/components/Sidebar.tsx +++ b/src/app/dashboard/components/Sidebar.tsx @@ -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'; @@ -71,7 +72,7 @@ export const Sidebar = () => {

{open ? 'Organization' : ''}

-
+

{open ? 'Main menu' : ''}

@@ -93,7 +94,7 @@ export const Sidebar = () => {
-
+

{open ? 'General' : ''}

@@ -113,17 +114,17 @@ export const Sidebar = () => { {open ? Support : ''} - {/* - + - {open ? Settings : ''} - */} + {open ? Referral : ''} +
diff --git a/src/assets/Svg/Account/Account.tsx b/src/assets/Svg/Account/Account.tsx index 69b3baa5..64672035 100644 --- a/src/assets/Svg/Account/Account.tsx +++ b/src/assets/Svg/Account/Account.tsx @@ -113,6 +113,29 @@ export const CopyPasteSvg = () => { ); }; +export const ReferalSvg = () => { + return ( + + + + + + ); +}; export const CheckSquareValid = () => { return (