You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import type { NextPage } from 'next'
  2. import { useSession } from 'next-auth/react';
  3. import Head from 'next/head'
  4. import { Box } from '@mui/system';
  5. import Hero from '../components/hero/Hero';
  6. import { getFeaturedProducts } from '../requests/products/featuredProductsRequest';
  7. import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
  8. import FeaturedProductsList from '../components/products/featured-products-list/FeaturedPorductsList';
  9. import Features from '../components/features/Features';
  10. import CompanyInfo from '../components/company-info/CompanyInfo';
  11. import { useUserUpdate } from '../store/user-context';
  12. import { getStorage } from '../utils/helpers/storage';
  13. import { useEffect } from 'react';
  14. import { ProductDataDB } from '../utils/interface/productInterface';
  15. interface Props {
  16. data: { featuredProducts: ProductDataDB[], message: string };
  17. }
  18. const Home: NextPage<Props> = ({ data }) => {
  19. const { data: session } = useSession();
  20. const { addUser } = useUserUpdate();
  21. useEffect(() => {
  22. const userData = getStorage('user-data');
  23. if (session?.user && userData.length === 0) {
  24. addUser(session.user);
  25. }
  26. }, [session, addUser]);
  27. return (
  28. <>
  29. <Box sx={{ width: '100%', height: '100%' }}>
  30. <Head>
  31. <title>Coffee Shop</title>
  32. <meta name="description" content="Random data with pagination..." />
  33. </Head>
  34. <Hero />
  35. <FeaturedProductsList
  36. featuredProducts={data.featuredProducts}
  37. ></FeaturedProductsList>
  38. <Features />
  39. <CompanyInfo />
  40. </Box>
  41. </>
  42. )
  43. }
  44. export async function getStaticProps({ locale }: any) {
  45. try {
  46. const data = await getFeaturedProducts();
  47. return {
  48. props: {
  49. ...(await serverSideTranslations(locale, ["home"])),
  50. data: data
  51. },
  52. };
  53. } catch (error) {
  54. return {
  55. props: {
  56. ...(await serverSideTranslations(locale, ['home'])),
  57. featuredProducts: [],
  58. },
  59. };
  60. }
  61. }
  62. export default Home