Skip to content

Commit

Permalink
Merge pull request #240 from piyushyadav1617/dev-branch
Browse files Browse the repository at this point in the history
referral link for signup page
  • Loading branch information
moonlightnexus authored Nov 13, 2023
2 parents 8b5b15f + ab4514c commit 6eed4e3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
17 changes: 13 additions & 4 deletions src/app/(signup)/signup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type RequestObjectType = {
type RegisterUser = {
username: string;
password: string;
'referral-id': string | null | undefined;
ref: string | null | undefined;
agreeTerms: boolean | undefined;
};

Expand All @@ -48,7 +48,7 @@ const registerSchema = yup
/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d_.@$!%#?&]{8,1000}$/,
'Password must be at least 8 characters long, contain at least one letter and one digit, and can include special characters.'
),
'referral-id': yup.string().nullable(),
ref: yup.string().nullable(),
agreeTerms: yup
.boolean()
.oneOf([true], 'Please accept our Terms of Service and Privacy policy')
Expand Down Expand Up @@ -88,6 +88,7 @@ export default function Signup() {
const [alert, setAlert] = useState(false);
const [alertMessage, setAlertMessage] = useState('');
const [requestObject, setRequestObject] = useState<RequestObjectType>();
const [refId, setRefId] = useState<string>('string');
const {
register,
handleSubmit,
Expand All @@ -100,6 +101,12 @@ export default function Signup() {
//OTP should be 8 digits long and all the digits should not be zero
return /^(?!.*00000000)\d{8}$/.test(otp);
};
useEffect(() => {
const ref_id = window.localStorage.getItem('ref_id');
setRefId(ref_id ?? 'string');
console.log(ref_id);
}, []);

// OTP action
useEffect(() => {
if (otp.length === 8) {
Expand Down Expand Up @@ -220,7 +227,7 @@ export default function Signup() {
full_name: 'Test User',
is_pool: true,
link: true,
ref: 'string',
ref: refId,
types: 'string'
};

Expand Down Expand Up @@ -295,7 +302,9 @@ export default function Signup() {
Referral ID (Optional)
</label>
<input
{...register('referral-id')}
{...register('ref')}
value={refId}
disabled
id="referral-id"
type="text"
className="form-control w-full px-8 py-3 border border-slate-500 rounded-lg"
Expand Down
5 changes: 4 additions & 1 deletion src/app/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ const Login = ({ searchParams }: { searchParams: Record<string, string> }) => {

useEffect(() => {
const token = searchParams['tnx'];
setRefId(searchParams['ref']);
const ref_id = searchParams['ref'];
setRefId(ref_id);
// console.log(ref_id)
window.localStorage.setItem('ref_id', ref_id);

if (token)
signIn('credentials', {
Expand Down Expand Up @@ -134,6 +136,7 @@ const Login = ({ searchParams }: { searchParams: Record<string, string> }) => {
</div>
{!values.username ? (
<EmailComponent
ref_id={refId}
handleEmailSubmit={handleEmailSubmit}
setFa2={setFa2}
/>
Expand Down
4 changes: 3 additions & 1 deletion src/components/authForm/EmailComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import { UserResponse } from '@/types';
type EmailSubmitType = {
handleEmailSubmit: (data: { username: string }) => void;
setFa2: React.Dispatch<React.SetStateAction<boolean>>;
ref_id: string;
};

export const EmailComponent = ({
handleEmailSubmit,
setFa2
setFa2,
ref_id
}: EmailSubmitType) => {
// email validation
const asyncEmailValidation = async (email: string) => {
Expand Down

0 comments on commit 6eed4e3

Please sign in to comment.