Advertisement
Guest User

Home.tsx

a guest
Nov 2nd, 2023
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { IonContent, IonPage } from '@ionic/react';
  2. import { Swiper, SwiperSlide } from 'swiper/react';
  3. import { Box, Typography } from '@mui/material';
  4.  
  5. import {
  6.   ArticleCard,
  7.   Button,
  8.   ClinicInformationCard,
  9.   VSpacer,
  10. } from '../../../components/DesignSystem';
  11. import { Color } from '../../../theme/MUITheme/colors';
  12. import EmergencyIcon from '../../../components/icons/EmergencyIcon';
  13. import { useEffect, useState } from 'react';
  14. import { IArticle } from '@libs/shared';
  15. import { ArticleApi } from '../../../services/ApiService/Article';
  16. import { ActionButtonCard } from '../../../components/DesignSystem';
  17.  
  18. import './Home.scss';
  19. import { useHistory } from 'react-router';
  20.  
  21. const EmergencyHandler = () => {
  22.   // TODO: Implement emergency handler
  23. };
  24.  
  25. const ClinicHandler = () => {
  26.   // TODO: Implement clinic handler
  27. };
  28.  
  29. const HelpHandler = () => {
  30.   // TODO: Implement help handler
  31. };
  32.  
  33. export default function HomeAuth() {
  34.   const [articles, setArticles] = useState<IArticle[] | [] | null>(null);
  35.   const router = useHistory();
  36.  
  37.   async function getArticles() {
  38.     try {
  39.       const articles = await ArticleApi.getAllArticles();
  40.       setArticles(articles);
  41.     } catch (error) {
  42.       console.error(error);
  43.       return null;
  44.     }
  45.   }
  46.  
  47.   useEffect(() => {
  48.     getArticles();
  49.   }, []);
  50.  
  51.   return (
  52.     <IonPage>
  53.       <IonContent>
  54.         <header
  55.           id="header"
  56.           style={{
  57.             margin: '0',
  58.             height: '220px',
  59.             padding: '0 14px 21px',
  60.             background: `linear-gradient(224deg, ${Color.primary.main} 31.96%, rgba(179, 65, 182, 0.97) 81.57%)`,
  61.           }}
  62.         >
  63.           <Box sx={{ margin: '0 0 25px 0' }}>
  64.             <Typography variant="h1" color={Color.neutral.white} fontSize="16px" fontWeight={700}>
  65.               Recuerda que puedas iniciar sesión o registrarte para obtener beneficios adicionales.
  66.             </Typography>
  67.             <VSpacer size="2" />
  68.             <Button
  69.               color={Color.neutral.white}
  70.               sx={{
  71.                 color: Color.primary.main,
  72.                 padding: '10px 20px',
  73.                 fontSize: '12px',
  74.                 '&:hover': {
  75.                   backgroundColor: Color.neutral.white,
  76.                   color: Color.primary.main,
  77.                 },
  78.               }}
  79.               testID="home-auth"
  80.               variant="contained"
  81.               id="auth-button"
  82.               onClick={() => router.push('/login')}
  83.             >
  84.               Iniciar sesión / Registrarse
  85.             </Button>
  86.           </Box>
  87.           <Box sx={{ margin: '0', padding: '0' }}>
  88.             <img
  89.               src="/assets/images/3d-casual-life-girl-holding-laptop-and-having-an-idea-1.png"
  90.               alt="Girl with a holding laptop"
  91.               style={{ maxWidth: '110px' }}
  92.             />
  93.           </Box>
  94.         </header>
  95.         <main
  96.           style={{
  97.             padding: '27px 14px 0 14px',
  98.             margin: '-25px 0 0 0',
  99.             minHeight: '80vh',
  100.             borderRadius: '30px 30px 0 0',
  101.             background: Color.primary.light1,
  102.           }}
  103.         >
  104.           <section>
  105.             <Typography
  106.               variant="h1"
  107.               margin="0"
  108.               fontSize="18px"
  109.               fontWeight={700}
  110.               color={Color.primary.main}
  111.             >
  112.               ¿Qué necesitas?
  113.             </Typography>
  114.             <VSpacer size="5" />
  115.             <Box display="flex" justifyContent="space-around" alignItems="center">
  116.               <ActionButtonCard
  117.                 className="action-button-card"
  118.                 name="Clínicas"
  119.                 image="/assets/images/3d-casual-life-hospital.png"
  120.                 onClick={ClinicHandler}
  121.               />
  122.  
  123.               <ActionButtonCard
  124.                 className="action-button-card"
  125.                 name="Ayuda"
  126.                 image="/assets/images/3d-white-dog-talking-standing.png"
  127.                 onClick={HelpHandler}
  128.               />
  129.             </Box>
  130.             <VSpacer size="7" />
  131.             <Box display="flex" justifyContent="space-around" alignItems="center">
  132.               <Button
  133.                 onClick={EmergencyHandler}
  134.                 color={Color.semantic.red.main}
  135.                 testID="emergency-button"
  136.                 accessoryLeft={<EmergencyIcon color="#fff" />}
  137.               >
  138.                 Emergencia
  139.               </Button>
  140.             </Box>
  141.           </section>
  142.           <VSpacer size="6" />
  143.           <section>
  144.             <Typography variant="h1" fontSize="18px" fontWeight={700} color={Color.primary.main}>
  145.               Sugerencias
  146.             </Typography>
  147.             <VSpacer size="7" />
  148.             <Typography variant="body1" color={Color.neutral.black} fontSize="12px">
  149.               Cercanos a mi ubicación
  150.             </Typography>
  151.             <VSpacer size="4" />
  152.             <Swiper style={{ margin: '0 -22px 0 0' }} spaceBetween="12px" slidesPerView="auto">
  153.               {/* TODO: show recommendations for user */}
  154.               {Array.from({ length: 5 }).map((_, index) => (
  155.                 <SwiperSlide key={index} style={{ width: '231px' }}>
  156.                   <ClinicInformationCard
  157.                     clinicInformation={{
  158.                       name: 'Veterinaria Lola',
  159.                       directPhone: '0414-4555555',
  160.                       address: {
  161.                         main: 'Avenida Bolivar',
  162.                         state: 'Caracas',
  163.                         city: 'Caracas',
  164.                         secondary: 'd',
  165.                         postalCode: '4505',
  166.                       },
  167.                       rating: 5.2,
  168.                       pictures: ['d'],
  169.                       taxId: 'id',
  170.                       paymentMethods: [{ value: 'ho' }],
  171.                     }}
  172.                   />
  173.                 </SwiperSlide>
  174.               ))}
  175.             </Swiper>
  176.           </section>
  177.           <VSpacer size="6" />
  178.           <section>
  179.             <Typography variant="body1" color={Color.neutral.black} fontSize="12px">
  180.               Artículos
  181.             </Typography>
  182.             <VSpacer size="4" />
  183.             <Swiper style={{ margin: '0 -22px 0 0' }} spaceBetween="12px" slidesPerView="auto">
  184.               {articles ? (
  185.                 articles.map((article) => (
  186.                   <SwiperSlide key={article.id} style={{ width: '170px' }}>
  187.                     <ArticleCard name={article.title ?? ''} link={`/articles/${article.id}`} />
  188.                   </SwiperSlide>
  189.                 ))
  190.               ) : (
  191.                 <Typography variant="caption2">Nada para mostrar</Typography>
  192.               )}
  193.             </Swiper>
  194.           </section>
  195.         </main>
  196.       </IonContent>
  197.     </IonPage>
  198.   );
  199. }
  200.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement