-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
v4lentinag
committed
May 16, 2024
1 parent
88b5414
commit dc9f8d2
Showing
15 changed files
with
2,736 additions
and
1,548 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use client' | ||
|
||
import axios from '@/lib/axios' | ||
import CardCommon from './cardCommon' | ||
import { useState, useEffect } from 'react' | ||
import { useAuth } from '@/hooks/auth' | ||
import { v4 as uuidv4 } from 'uuid' | ||
|
||
const CardList = () => { | ||
const { user } = useAuth({ middleware: 'auth' }) | ||
const { code } = useAuth() | ||
const [list, setList] = useState([]) | ||
const codeUnique = uuidv4() | ||
|
||
useEffect(() => { | ||
axios | ||
.get('/api/list_offers') | ||
.then(response => { | ||
// Actualizar el estado con los datos de las ofertas recibidas | ||
setList(response.data) | ||
}) | ||
.catch(error => { | ||
console.error('Error fetching offers:', error) | ||
}) | ||
}, []) | ||
|
||
const handleCode = () => { | ||
list.forEach(offer => { | ||
code({ | ||
code: codeUnique, | ||
user_id: user.id, | ||
offer_id: offer.id, | ||
redeemed: false, | ||
}) | ||
}) | ||
} | ||
return ( | ||
<> | ||
{list && | ||
list.map(offer => ( | ||
<CardCommon | ||
key={offer.id} | ||
title={offer.name} | ||
discount={offer.discount} | ||
image={offer.image_url} | ||
description={offer.description} | ||
buttonText={'Obtener'} | ||
handlerClick={handleCode} | ||
/> | ||
))} | ||
</> | ||
) | ||
} | ||
|
||
export default CardList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Button } from '@mui/material' | ||
|
||
const ButtonCommon = ({ title, handleClick, variant, href, ...props }) => { | ||
return ( | ||
<Button onClick={handleClick} variant={variant} href={href} {...props}> | ||
{title} | ||
</Button> | ||
) | ||
} | ||
|
||
export default ButtonCommon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as React from 'react' | ||
import Card from '@mui/material/Card' | ||
import CardContent from '@mui/material/CardContent' | ||
import CardMedia from '@mui/material/CardMedia' | ||
import Typography from '@mui/material/Typography' | ||
import { Box, CardActionArea, CardActions } from '@mui/material' | ||
import { styled } from '@mui/material/styles' | ||
import ButtonCommon from './buttonCommon' | ||
|
||
const ButtonStyledLogin = styled(ButtonCommon)({ | ||
color: 'white', | ||
backgroundColor: '#715aff', | ||
'&:hover': { | ||
backgroundColor: '#5830f7', | ||
}, | ||
}) | ||
|
||
export default function CardCommon({ | ||
title, | ||
image, | ||
description, | ||
discount, | ||
buttonText, | ||
handlerClick, | ||
}) { | ||
return ( | ||
<Card sx={{ maxWidth: 345 }}> | ||
<CardActionArea> | ||
<div | ||
style={{ | ||
height: 250, | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}}> | ||
<div style={{ width: 150, height: 150 }}> | ||
<CardMedia component="img" image={image} alt={title} /> | ||
</div> | ||
</div> | ||
<CardContent> | ||
<Typography | ||
textAlign="center" | ||
gutterBottom | ||
variant="h5" | ||
component="div"> | ||
{title} | ||
</Typography> | ||
<Typography textAlign="center" variant="h6" component="div"> | ||
{'% ' + discount + ' DESCUENTO'} | ||
</Typography> | ||
<Typography | ||
textAlign="center" | ||
variant="body2" | ||
color="text.secondary"> | ||
{description} | ||
</Typography> | ||
</CardContent> | ||
</CardActionArea> | ||
<CardActions> | ||
<Box width="100%" display="flex" justifyContent="center"> | ||
<ButtonStyledLogin | ||
handleClick={handlerClick} | ||
style={{ width: 150, height: 40, marginBottom: 20 }} | ||
size="small" | ||
variant={'contained'} | ||
title={buttonText} | ||
/> | ||
</Box> | ||
</CardActions> | ||
</Card> | ||
) | ||
} |
Oops, something went wrong.