Skip to content

Commit

Permalink
Merge pull request #131 from wizelineacademy/deployment-fix
Browse files Browse the repository at this point in the history
Fix login and logout issues
  • Loading branch information
JulioEmmmanuel authored Jun 3, 2024
2 parents 9b6d979 + 6c26808 commit 28c69ef
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/app/(pages)/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const Login = () => {
icon={FcGoogle}
onClick={() =>
signIn('google', {
callbackUrl: '/home',
callbackUrl: '/healthdata',
})
}
/>
Expand All @@ -150,7 +150,7 @@ const Login = () => {
icon={FaFacebook}
onClick={() =>
signIn('facebook', {
callbackUrl: '/home',
callbackUrl: '/healthdata',
})
}
/>
Expand Down
91 changes: 53 additions & 38 deletions src/app/(pages)/(main)/nutrition/page.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,66 @@
'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
* @version 2.0.0
* 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<number[]>([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<SelectPortions>('/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 (
<div className='mb-4'>
{/* Title */}
Expand All @@ -62,16 +77,16 @@ const Nutrition = () => {
{/* Displaying portion numbers and corresponding images */}
<div className='flex flex-col items-center justify-center md:justify-start lg:justify-start'>
<div className='ml-4 flex w-[160px] flex-wrap rounded-3xl bg-custom-lightpurple px-5 sm:w-[330px] md:w-[360px] lg:w-[500px]'>
{numeros.map((numero, index) => (
{portions.map((portion, index) => (
<div
key={index}
className='mx-4 my-2 flex flex-col items-center py-2 sm:mx-6 md:mx-2 lg:mx-4'
>
<h3 className='text-2xl text-white md:text-3xl lg:text-3xl'>
{numero.number}
{portion}
</h3>
<Image
src={numero.imageSrc}
src={icons[index]}
alt={`Imagen ${index}`}
width={24}
height={24}
Expand Down
2 changes: 1 addition & 1 deletion src/app/(pages)/healthdata/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const HealthData = () => {
if (!data) {
return
} else {
router.replace('/plan')
router.replace('/home')
}
} catch (error) {
console.log(error)
Expand Down
2 changes: 1 addition & 1 deletion src/components/sidebar/SidebarInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const SidebarInfo = () => {
<Link
onClick={() => {
if (route.label === 'Cerrar sesión') {
signOut()
signOut({ callbackUrl: '/' })
}
}}
href={route.href}
Expand Down
2 changes: 2 additions & 0 deletions src/db/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ export const portionsNutrition = pgTable('PortionsNutrition', {
fat: integer('fat').notNull(),
})

export type SelectPortions = InferSelectModel<typeof portionsNutrition>

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

0 comments on commit 28c69ef

Please sign in to comment.