Skip to content

Commit

Permalink
#221 referral scope
Browse files Browse the repository at this point in the history
  • Loading branch information
SixStringer91 committed Oct 7, 2022
1 parent 7b25716 commit 85f2ca4
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 76 deletions.
14 changes: 8 additions & 6 deletions ui/front/src/apps/web/components/app.container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Route, Routes } from 'react-router-dom';
import {
Notifications,
Preload,
DownloadPage, NavButton
DownloadPage, NavButton, FailPage
} from '@components/shared';
import { PreloadComponent } from '@components/hoc';
import {
Expand Down Expand Up @@ -112,10 +112,6 @@ function Main() {
path="/onboarding"
element={<OnboardingStep />}
/>
<Route
path="/referral-programm"
element={<ReferralProgramm />}
/>
<Route
path="/download"
element={<DownloadPage />}
Expand All @@ -138,7 +134,13 @@ function Main() {
<ErrorBoundary>
<Routes>
<Route path="/" element={<Lendos />} />
<Route path="/*" element={routes} />
<Route
path="/referral-programm"
element={<ReferralProgramm />}
/>
{/* <Route path="/*" element={routes} /> */}
<Route path="/*" element={<FailPage />} />

</Routes>
</ErrorBoundary>
<Notifications />
Expand Down
34 changes: 17 additions & 17 deletions ui/front/src/apps/web/components/header/header.container.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
AutocompeteSearch,
ConnectBtn,
// AutocompeteSearch,
// ConnectBtn,
ProfileBlock
} from '@components/shared';
import { Link } from 'react-router-dom';
Expand All @@ -23,12 +23,12 @@ function Header({ isOnLending, desktop }:HeaderPropsType) {
const {
pkey,
users,
isVisible,
onConnect
isVisible
// onConnect
} = containerProps;

const isAuth = Boolean(useSelector((state) => state.profile.data.token));
const autoCompleteClassName = isOnLending ? styles.lendosInput : '';
// const autoCompleteClassName = isOnLending ? styles.lendosInput : '';

const headerClassName = isOnLending ? styles.header : styles.headerActive;

Expand All @@ -37,18 +37,18 @@ function Header({ isOnLending, desktop }:HeaderPropsType) {
<Link to="/">
<img className={styles.logo} alt="source" src={img} />
</Link>
{/*<ul className={[styles.navList, styles.textColor].join(' ')}>*/}
{/* <li>*/}
{/* <Link className={styles.textColor} to="/repos/all/1">*/}
{/* Repositories*/}
{/* </Link>*/}
{/* </li>*/}
{/* <li>*/}
{/* <Link className={styles.textColor} to="/organizations/all/1">*/}
{/* Organizations*/}
{/* </Link>*/}
{/* </li>*/}
{/*</ul>*/}
{/* <ul className={[styles.navList, styles.textColor].join(' ')}> */}
{/* <li> */}
{/* <Link className={styles.textColor} to="/repos/all/1"> */}
{/* Repositories */}
{/* </Link> */}
{/* </li> */}
{/* <li> */}
{/* <Link className={styles.textColor} to="/organizations/all/1"> */}
{/* Organizations */}
{/* </Link> */}
{/* </li> */}
{/* </ul> */}
</div>
);

Expand Down
6 changes: 3 additions & 3 deletions ui/front/src/apps/web/components/lendos/lendos.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable max-len */
import img from '@assets/img/source-logo.svg';
import { GitConnectAuth } from '@components/shared/git-auth';
import { useNavigate } from 'react-router-dom';
// import { useNavigate } from 'react-router-dom';
import styles from './lendos.module.scss';

function Lendos() {
const navigate = useNavigate();
const onClick = () => navigate('/repos/all/1', { replace: false });
// const navigate = useNavigate();
// const onClick = () => navigate('/repos/all/1', { replace: false });
return (
<div className={styles.bg}>
<div className={styles.wrapper}>
Expand Down
16 changes: 14 additions & 2 deletions ui/front/src/components/shared/git-auth/git-auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function GitConnectAuth({ name, small, why }:GitConnectAuthProps) {
redirect_uri={`${window.location.origin}/git-auth`}
onResolve={({ data }) => {
console.log({ data });
axios.get(`${HOST}/login?code=${data.code}${refId ? `&ref_by=${refId}` : ''}`)
const ref = refId ? `&ref_by=${refId}` : '';
axios.get(`${HOST}/login?code=${data.code}${ref}`)
.then((res) => {
console.log(res.data.token);
window.localStorage.setItem('token', res.data.token);
Expand Down Expand Up @@ -96,7 +97,18 @@ function GitConnectAuth({ name, small, why }:GitConnectAuthProps) {
active
/>
</LoginSocialGithub>
{why && !isDisabled && <a className={styles.whyLink} target="_blank" href="https://www.sourc3.xyz/why-connect-to-github" rel="noreferrer">Why connect? Learn more</a>}
{why
&& !isDisabled
&& (
<a
className={styles.whyLink}
target="_blank"
href="https://www.sourc3.xyz/why-connect-to-github"
rel="noreferrer"
>
Why connect? Learn more
</a>
)}
</div>
<Popup
visible={isVisible}
Expand Down
158 changes: 110 additions & 48 deletions ui/front/src/components/shared/referral-programm/referralProgramm.tsx
Original file line number Diff line number Diff line change
@@ -1,54 +1,116 @@
import { NavButton, Preload } from '@components/shared';
import { useFetch } from '@libs/hooks/shared';
import { useSelector } from '@libs/redux';
import { NotificationPlacement } from '@types';
import { message, notification } from 'antd';
import { useCallback, useEffect, useMemo } from 'react';
import { HOST } from '../git-auth/profile/constants';
import styles from './referralProgramm.module.scss';

import styles from './referralProgramm.module.scss'
import {NavButton} from "@components/shared";
import React from "react";
type Referral = {
user_id: number,
github_login:string,
created_at: string
};

type RefferalsResponce = {
referred_by: number | null,
referrals: Referral[]
};

const formatDate = (dateString:string) => {
const options:Intl.DateTimeFormatOptions = {
year: 'numeric', month: 'long', day: 'numeric'
};

const date = new Date(dateString);

const dayAndYear = date.toLocaleString('en', options);
const time = date.toLocaleString('en', { timeStyle: 'short' });
return `${dayAndYear} ${time}`;
};

function ReferralProgramm() {
const id = useSelector((state) => state.profile.data.id);

const token = localStorage.getItem('token');
const { data, loading, error } = useFetch<RefferalsResponce>(`${HOST}/user/referrals`, {
method: 'GET',
headers: {
Authorization: `Bearer ${token}`
}
});

const handleCopyRefLink = useCallback(() => {
if (id) {
const repoLink = `${window.location.origin}/?ref_by=${id}`;
navigator.clipboard.writeText(repoLink);
return message.info(`${repoLink} copied to clipboard!`);
} return message.error('Cannot create ref link');
}, [id]);

useEffect(() => {
if (error) {
notification.error({
message: 'connection failed',
placement: 'bottomRight' as NotificationPlacement
});
}
}, [error]);

const referrals = useMemo(() => {
if (loading) return <Preload message="loading data..." />;
if (data) {
return (
<>
{
data.referrals.map((el) => (
<div key={`user_id-${el.user_id}`} className={styles.info}>
<p>{formatDate(el.created_at)}</p>
<p>10</p>
</div>
))
}
</>
);
}
return (
<div className={styles.section}>
<h1>Referral program</h1>
<div className={styles.content}>
<div className={styles.text}>
<h4>You have 50 referral points</h4>
<p>Your referral score will entitle you to future benefits and airdrops. Use your SOURC3 referral link to spread the Web3 word.</p>
<NavButton
name="Copy referral link"
/>
</div>
<div className={styles.table}>
<div className={styles.title}>
<h4>Activation date</h4>
<h4>Referral points</h4>
</div>
<div className={styles.date}>
{/*<div className={styles.empty}>*/}
{/* <p>No one have used your referral link so far</p>*/}
{/*</div>*/}

<div className={styles.info}>
<p>11 Oct 2022, 4:56 PM</p>
<p>10</p>
</div>
<div className={styles.info}>
<p>11 Oct 2022, 4:56 PM</p>
<p>10</p>
</div>
<div className={styles.info}>
<p>11 Oct 2022, 4:56 PM</p>
<p>10</p>
</div>
<div className={styles.info}>
<p>11 Oct 2022, 4:56 PM</p>
<p>10</p>
</div>
<div className={styles.info}>
<p>11 Oct 2022, 4:56 PM</p>
<p>10</p>
</div>
</div>
</div>
</div>
</div>
<div className={styles.empty}>
<p>No one have used your referral link so far</p>
</div>
);
}, [data, loading]);

const title = useMemo(() => {
const count = !data?.referrals ? '...'
: data?.referrals.length as number * 10 || 0;
const msg = `You have ${count} referral points`;
return <h4>{msg}</h4>;
}, [data, loading]);

return (
<div className={styles.section}>
<h1>Referral program</h1>
<div className={styles.content}>
<div className={styles.text}>
{title}
<p>Your referral score will entitle you to future benefits and airdrops. Use your SOURC3 referral link to spread the Web3 word.</p>
<NavButton
onClick={handleCopyRefLink}
name="Copy referral link"
/>
</div>
<div className={styles.table}>
<div className={styles.title}>
<h4>Activation date</h4>
<h4>Referral points</h4>
</div>
<div className={styles.date}>
{referrals}
</div>
</div>
</div>
</div>
);
}
export default ReferralProgramm;
export default ReferralProgramm;

0 comments on commit 85f2ca4

Please sign in to comment.