From b835a8c8458377d60dac340664ac165cbab52b42 Mon Sep 17 00:00:00 2001 From: Aravind Balla Date: Sun, 14 Jul 2024 12:35:36 +0530 Subject: [PATCH] feat: wishlist auth --- pages/wishlist.js | 135 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 114 insertions(+), 21 deletions(-) diff --git a/pages/wishlist.js b/pages/wishlist.js index 7eeee8c..720487c 100644 --- a/pages/wishlist.js +++ b/pages/wishlist.js @@ -1,8 +1,13 @@ +import { useEffect, useState } from 'react'; import { NextSeo } from 'next-seo'; +import { useSearchParams } from 'next/navigation'; +import { useRouter } from 'next/navigation'; import { baseUrl } from '../seo.config'; import Layout from '../components/Layout'; +const unallowedPeople = ['gautami', 'krushi']; + const gifts = { 'Coffee Stuff': { subheading: 'Yes, he owns a lot of coffee stuff. But there is always room for more.', @@ -88,6 +93,25 @@ const gifts = { }; export default function WishlistPage() { + const searchParams = useSearchParams(); + const show = searchParams.get('show'); + + const router = useRouter(); + + const [name, setName] = useState(''); + + useEffect(() => { + if (show === 'true') { + const wishlistName = localStorage.getItem('wishlistName'); + if (!wishlistName) { + router.push({ + pathname: '/wishlist', + search: ``, + }); + } + } + }, [show]); + return (

Wishlist 2024

-

- A surprise gift is best, but it should not go unused. -

- {Object.entries(gifts).map(([category, { subheading, items }]) => ( -
-

{category}

- {subheading &&

{subheading}

} -
    - {items.map((item) => ( -
  • - - {item.title} - {' '} - - ₹{item.price} - {/*
    */} - {/* {item.description} */} -
  • - ))} -
-
- ))} + {show === 'true' ? ( + <> +

+ A surprise gift is best, but it should not go unused. +

+

If you pick something, let Aravind know so he can strike it off here.

+ {Object.entries(gifts).map(([category, { subheading, items }]) => ( +
+

{category}

+ {subheading &&

{subheading}

} +
    + {items.map((item) => ( +
  • + + {item.title} + {' '} + - ₹{item.price} + {/*
    */} + {/* {item.description} */} +
  • + ))} +
+
+ ))} + + ) : ( +
{ + e.preventDefault(); + + if (unallowedPeople.includes(name.toLowerCase())) { + alert( + 'Sorry, you are not allowed to see the list. You might have already gifted something.' + ); + } else { + localStorage.setItem('wishlistName', name); + router.push({ + pathname: '/wishlist', + search: `show=true`, + }); + } + }} + > +
+

+ There no pressure to gift anything. Having you in his life is itself a gift for + Aravind. If you still insist, please proceed. +

+ { + setName(e.target.value); + }} + /> + +
+
+ +
+
+ +
+
+ +
+ +
+
+
+ )}
);