Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
BUCKET_NAME="YOUR_BUCKET_NAME"
AWS_REGION="YOUR_AWS_REGION"
CLOUDFRONT_DOMAIN="YOUR_CLOUDFRONT_DOMAIN"
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useState } from 'react'
import { motion, AnimatePresence } from 'framer-motion'
import Lottie from 'lottie-react'
import { format } from 'date-fns'
import { es } from 'date-fns/locale'
import { useRouter } from 'next/navigation'
Expand All @@ -14,6 +13,7 @@ import {
AlertDialogFooter,
} from '@/components/ui/alert-dialog'
import { Button } from '@/components/ui/button'
import dynamic from 'next/dynamic'
import cancelAnimation from '@/app/(main-layout)/account-settings/anim/cancel-animation.json'
import successAnimation from '@/app/(main-layout)/account-settings/anim/success-animation.json'

Expand All @@ -32,6 +32,11 @@ export function CancellationDialog({
isPendingFree,
expirationDate,
}: CancellationDialogProps) {
const LottieWrapper = dynamic(
() => import('@/app/(main-layout)/account-settings/components/LottieWrapper'),
{ ssr: false }
)

const [isOpen, setIsOpen] = useState(false)
const [isCancelled, setIsCancelled] = useState(false)
const router = useRouter()
Expand Down Expand Up @@ -80,7 +85,7 @@ export function CancellationDialog({
>
<AlertDialogHeader>
<div className="mx-auto w-32 h-32 mb-4">
<Lottie animationData={cancelAnimation} loop={true} />
<LottieWrapper animationData={cancelAnimation} />
</div>
<AlertDialogTitle className="text-center">
¿Estás seguro de cancelar tu suscripción?
Expand Down Expand Up @@ -118,7 +123,7 @@ export function CancellationDialog({
>
<AlertDialogHeader>
<div className="mx-auto w-32 h-32 mb-4 mt-2">
<Lottie animationData={successAnimation} loop={false} />
<LottieWrapper animationData={successAnimation} />
</div>
<AlertDialogTitle className="text-center">
Tu suscripción ha sido cancelada
Expand Down
12 changes: 12 additions & 0 deletions app/(main-layout)/account-settings/components/LottieWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use client'

import Lottie from 'lottie-react'

interface LottieWrapperProps {
animationData: object
loop?: boolean
}

export default function LottieWrapper({ animationData, loop = true }: LottieWrapperProps) {
return <Lottie animationData={animationData} loop={loop} />
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,26 @@ export function useUpdateProfilePicture() {
},
}).result

// 2. Construir la URL pública manualmente.
// 2. Construir la URL pública condicionalmente.
const bucketName = process.env.NEXT_PUBLIC_S3_URL
const awsRegion = process.env.NEXT_PUBLIC_AWS_REGION
const cloudFrontDomain = process.env.NEXT_PUBLIC_CLOUDFRONT_DOMAIN

if (!bucketName) {
throw new Error('There is no bucket for profile pictures')
throw new Error('NEXT_PUBLIC_S3_URL is not defined in your environment variables')
}

const publicUrl = `${bucketName}/${result.path}`
let publicUrl: string
const s3Key = result.path

if (cloudFrontDomain && cloudFrontDomain.trim() !== '') {
// Usar CloudFront para producción (o cuando esté configurado)
publicUrl = `https://${cloudFrontDomain}/${s3Key}`
} else {
// Fallback a la URL de S3 para otros entornos
const regionForS3Url = awsRegion
publicUrl = `https://${bucketName}.s3.${regionForS3Url}.amazonaws.com/${s3Key}`
}

// 3. Actualizar el atributo 'picture' del usuario con la URL pública.
await updateUserAttributes({
Expand Down
13 changes: 1 addition & 12 deletions app/(main-layout)/account-settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { AccountSettings } from '@/app/(main-layout)/account-settings/components
import { PaymentSettings } from '@/app/(main-layout)/account-settings/components/PaymentSettings'
import { ActiveSessions } from '@/app/(main-layout)/account-settings/components/ActiveSessions'
import { useState, useEffect, Suspense } from 'react'
import { Loader } from '@/components/ui/loader'
import { Amplify } from 'aws-amplify'
import { useSearchParams } from 'next/navigation'
import useUserStore from '@/context/core/userStore'
Expand Down Expand Up @@ -67,17 +66,7 @@ function AccountSettingsContent() {
export default function AccountSettingsPage() {
return (
<div className="overflow-x-hidden">
<Suspense
fallback={
<Loader
color="black"
content="Cargando perfil"
size="large"
fullWidth={true}
centered={true}
/>
}
>
<Suspense>
<AccountSettingsContent />
</Suspense>
</div>
Expand Down
25 changes: 21 additions & 4 deletions app/store/hooks/useLogoUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@ export function useLogoUpload(): UseLogoUploadReturn {
const [status, setStatus] = useState<UploadStatus>('idle')
const [error, setError] = useState<string | null>(null)

// Obtener el bucket correcto para logos de tienda
// Obtener el bucket y la región desde las variables de entorno
const bucketName = process.env.NEXT_PUBLIC_S3_URL
const awsRegion = process.env.NEXT_PUBLIC_AWS_REGION
const cloudFrontDomain = process.env.NEXT_PUBLIC_CLOUDFRONT_DOMAIN

if (!bucketName) {
throw new Error('There is no bucket for store logos')
throw new Error('environment variable NEXT_PUBLIC_S3_URL is not defined')
}

if (!awsRegion && (!cloudFrontDomain || cloudFrontDomain.trim() === '')) {
throw new Error(
'environment variable NEXT_PUBLIC_AWS_REGION is not defined or NEXT_PUBLIC_CLOUDFRONT_DOMAIN is not defined or empty'
)
}

const reset = () => {
Expand Down Expand Up @@ -61,8 +69,17 @@ export function useLogoUpload(): UseLogoUploadReturn {
},
}).result

// Construir la URL pública correcta usando el nombre del bucket
const publicUrl = `${bucketName}/${key}`
// Construir la URL pública condicionalmente
let publicUrl: string
const s3Key = result.path

if (cloudFrontDomain && cloudFrontDomain.trim() !== '') {
publicUrl = `https://${cloudFrontDomain}/${s3Key}`
} else {
// Fallback a la URL de S3
const regionForS3Url = awsRegion
publicUrl = `https://${bucketName}.s3.${regionForS3Url}.amazonaws.com/${s3Key}`
}

setStatus('success')

Expand Down
27 changes: 23 additions & 4 deletions app/store/hooks/useProductImageUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@ export function useProductImageUpload() {
const [isLoading, setIsLoading] = useState(false)
const [error, setError] = useState<Error | null>(null)

// Obtener el bucket correcto para imágenes de productos
// Obtener el bucket, la región y el dominio del CDN desde las variables de entorno
const bucketName = process.env.NEXT_PUBLIC_S3_URL
const awsRegion = process.env.NEXT_PUBLIC_AWS_REGION
const cloudFrontDomain = process.env.NEXT_PUBLIC_CLOUDFRONT_DOMAIN

if (!bucketName) {
throw new Error('There is no bucket for product images')
throw new Error('environment variable NEXT_PUBLIC_S3_URL is not defined')
}
// Es bueno tener awsRegion si se usa el fallback a S3
if (!awsRegion && (!cloudFrontDomain || cloudFrontDomain.trim() === '')) {
throw new Error(
'environment variable NEXT_PUBLIC_AWS_REGION is not defined or NEXT_PUBLIC_CLOUDFRONT_DOMAIN is not defined or empty'
)
}

const uploadProductImage = async (file: File, storeId: string): Promise<UploadedImage | null> => {
Expand All @@ -44,8 +52,19 @@ export function useProductImageUpload() {
data: file,
}).result

// Construir la URL pública correcta usando el nombre del bucket
const publicUrl = `${bucketName}/${result.path}`
// Construir la URL pública condicionalmente
let publicUrl: string
const s3Key = result.path

if (cloudFrontDomain && cloudFrontDomain.trim() !== '') {
// Usar CloudFront (generalmente para producción o cuando esté configurado)
publicUrl = `https://${cloudFrontDomain}/${s3Key}`
} else {
// Fallback a la URL de S3
const regionForS3Url = awsRegion
publicUrl = `https://${bucketName}.s3.${regionForS3Url}.amazonaws.com/${s3Key}`
}

return {
url: publicUrl,
alt: '',
Expand Down
5 changes: 5 additions & 0 deletions next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ const nextConfig = {
hostname: 'd1etr7t5j9fzio.cloudfront.net',
port: '',
},
{
protocol: 'https',
hostname: 'cdn.fasttify.com',
port: '',
},
],
},
}
Expand Down