From 6f1fe9930a489098151b207bf429dd82cf8f478e Mon Sep 17 00:00:00 2001 From: julio2505 Date: Sun, 2 Jun 2024 17:53:03 -0600 Subject: [PATCH 1/2] Fix login and logout issues --- src/app/(pages)/(auth)/login/page.tsx | 4 ++-- src/app/(pages)/healthdata/page.tsx | 2 +- src/components/sidebar/SidebarInfo.tsx | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/(pages)/(auth)/login/page.tsx b/src/app/(pages)/(auth)/login/page.tsx index ed9cd76b..b8c4b77c 100644 --- a/src/app/(pages)/(auth)/login/page.tsx +++ b/src/app/(pages)/(auth)/login/page.tsx @@ -138,7 +138,7 @@ const Login = () => { icon={FcGoogle} onClick={() => signIn('google', { - callbackUrl: '/home', + callbackUrl: '/healthdata', }) } /> @@ -150,7 +150,7 @@ const Login = () => { icon={FaFacebook} onClick={() => signIn('facebook', { - callbackUrl: '/home', + callbackUrl: '/healthdata', }) } /> diff --git a/src/app/(pages)/healthdata/page.tsx b/src/app/(pages)/healthdata/page.tsx index 5ceb46ee..5fa8991f 100644 --- a/src/app/(pages)/healthdata/page.tsx +++ b/src/app/(pages)/healthdata/page.tsx @@ -46,7 +46,7 @@ const HealthData = () => { if (!data) { return } else { - router.replace('/plan') + router.replace('/home') } } catch (error) { console.log(error) diff --git a/src/components/sidebar/SidebarInfo.tsx b/src/components/sidebar/SidebarInfo.tsx index 85ef72ab..7e8624e3 100644 --- a/src/components/sidebar/SidebarInfo.tsx +++ b/src/components/sidebar/SidebarInfo.tsx @@ -84,7 +84,7 @@ const SidebarInfo = () => { { if (route.label === 'Cerrar sesiĆ³n') { - signOut() + signOut({ callbackUrl: '/' }) } }} href={route.href} From 6c2680867ede534fa28e8b3911546d35c2f81c38 Mon Sep 17 00:00:00 2001 From: julio2505 Date: Sun, 2 Jun 2024 18:22:27 -0600 Subject: [PATCH 2/2] feat: Added portions in nutrition main --- src/app/(pages)/(main)/nutrition/page.tsx | 91 +++++++++++++---------- src/db/schema/schema.ts | 2 + 2 files changed, 55 insertions(+), 38 deletions(-) diff --git a/src/app/(pages)/(main)/nutrition/page.tsx b/src/app/(pages)/(main)/nutrition/page.tsx index 0aadf4d8..d1074e96 100644 --- a/src/app/(pages)/(main)/nutrition/page.tsx +++ b/src/app/(pages)/(main)/nutrition/page.tsx @@ -1,8 +1,11 @@ 'use client' -import React from 'react' +import React, { useEffect, useState } from 'react' import Image from 'next/image' import Link from 'next/link' +import axios from 'axios' +import { SelectPortions } from '@/src/db/schema/schema' +import Swal from 'sweetalert2' /** * @author: Bernardo de la Sierra @@ -10,42 +13,54 @@ import Link from 'next/link' * Component representing the Nutrition Home page */ const Nutrition = () => { - // Array containing objects with number and corresponding image source - const numeros = [ - { - number: 1, - imageSrc: '/icons/Grape.svg', - }, - { - number: 2, - imageSrc: '/icons/Carrot.svg', - }, - { - number: 3, - imageSrc: '/icons/Soy.svg', - }, - { - number: 4, - imageSrc: '/icons/Meat.svg', - }, - { - number: 5, - imageSrc: '/icons/Milk.svg', - }, - { - number: 6, - imageSrc: '/icons/Porridge.svg', - }, - { - number: 7, - imageSrc: '/icons/Sugar.svg', - }, - { - number: 8, - imageSrc: '/icons/Avocado.svg', - }, + const [portions, setPortions] = useState([0, 0, 0, 0, 0, 0, 0, 0]) + + const icons = [ + '/icons/Grape.svg', + '/icons/Carrot.svg', + '/icons/Soy.svg', + '/icons/Meat.svg', + '/icons/Milk.svg', + '/icons/Porridge.svg', + '/icons/Sugar.svg', + '/icons/Avocado.svg', ] + const getPortions = async () => { + try { + const response = await axios.get('/api/portions') + const data = response.data + + if (!data) { + return + } + + const numPortions = [ + data.fruits, + data.vegetables, + data.legumes, + data.meat, + data.milk, + data.cereals, + data.sugar, + data.fat, + ] + + setPortions(numPortions) + } catch (error) { + Swal.fire({ + title: 'Error', + text: 'OcurriĆ³ un error al recuperar las porciones', + icon: 'error', + confirmButtonText: 'OK', + }) + } + } + + useEffect(() => { + getPortions() + }) + return (
{/* Title */} @@ -62,16 +77,16 @@ const Nutrition = () => { {/* Displaying portion numbers and corresponding images */}
- {numeros.map((numero, index) => ( + {portions.map((portion, index) => (

- {numero.number} + {portion}

{`Imagen + export const userDetail = pgTable('UserDetail', { idUserDetail: serial('id_user_detail').primaryKey().notNull(), idUser: integer('id_user')