/*eslint-disable*/ 'use client'; // import ManageSubscriptionButton from './ManageSubscriptionButton'; import Card from '@/components/card/Card'; import DashboardLayout from '@/components/layout'; import { HSeparator } from '@/components/separator/Separator'; import { Database } from '@/types_db'; import { handleRequest } from '@/utils/auth-helpers/client'; import { updateEmail, updateName } from '@/utils/auth-helpers/server'; import { Button, Flex, FormLabel, Input, Text, useColorModeValue } from '@chakra-ui/react'; import { User } from '@supabase/supabase-js'; import { redirect, useRouter } from 'next/navigation'; import { useState } from 'react'; type Subscription = Database['public']['Tables']['subscriptions']['Row']; type Product = Database['public']['Tables']['products']['Row']; type Price = Database['public']['Tables']['prices']['Row']; interface ProductWithPrices extends Product { prices: Price[]; } interface PriceWithProduct extends Price { products: Product | null; } interface SubscriptionWithProduct extends Subscription { prices: PriceWithProduct | null; } interface Props { user: User | null | undefined; products: ProductWithPrices[]; subscription: SubscriptionWithProduct | null; userDetails: { [x: string]: any } | null; } export default function Settings(props: Props) { const [isSubmitting, setIsSubmitting] = useState(false); const router = useRouter(); const textColor = useColorModeValue('#120F43', 'white'); const placeholderColor = useColorModeValue( { color: 'gray.500' }, { color: 'whiteAlpha.600' } ); const borderColor = useColorModeValue('gray.200', 'whiteAlpha.200'); // -------------- Input Value Handler -------------- const handleSubmitEmail = async (e: React.FormEvent) => { setIsSubmitting(true); // Check if the new email is the same as the old email if (e.currentTarget.newEmail.value === props.user.email) { e.preventDefault(); setIsSubmitting(false); return; } handleRequest(e, updateEmail, router); setIsSubmitting(false); }; const handleSubmitName = async (e: React.FormEvent) => { setIsSubmitting(true); // Check if the new name is the same as the old name if (e.currentTarget.fullName.value === props.user.user_metadata.full_name) { e.preventDefault(); setIsSubmitting(false); return; } handleRequest(e, updateName, router); setIsSubmitting(false); }; if (!props.user) { return redirect('/dashboard/signin'); } return ( <> Account Settings Here you can change your account information Your Name {' '} (30 characters maximum)
handleSubmitName(e)} >
{/* {nameError?.message} */} Your Email {' '} (We will email you to verify the change)
handleSubmitEmail(e)} >
); }