From 9f5b858ffb34d33678d8680175b812e994d451d3 Mon Sep 17 00:00:00 2001 From: isra el Date: Thu, 7 Aug 2025 20:33:20 +0300 Subject: [PATCH 1/2] chore(web): improve support form --- web/app/(app)/dashboard/(components)/support-form.tsx | 9 ++++++--- web/lib/auth.ts | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/web/app/(app)/dashboard/(components)/support-form.tsx b/web/app/(app)/dashboard/(components)/support-form.tsx index 4239dbb..a5d34fc 100644 --- a/web/app/(app)/dashboard/(components)/support-form.tsx +++ b/web/app/(app)/dashboard/(components)/support-form.tsx @@ -27,6 +27,7 @@ import { toast } from '@/hooks/use-toast' import httpBrowserClient from '@/lib/httpBrowserClient' import { ApiEndpoints } from '@/config/api' import { useRouter } from 'next/navigation' +import { useSession } from 'next-auth/react' const SupportFormSchema = z.object({ name: z.string().min(1, { message: 'Name is required' }), @@ -44,12 +45,14 @@ export default function SupportForm() { const [errorMessage, setErrorMessage] = useState(null) const router = useRouter() + const { data: session } = useSession() + const form = useForm({ resolver: zodResolver(SupportFormSchema), defaultValues: { - name: '', - email: '', - phone: '', + name: session?.user?.name || '', + email: session?.user?.email || '', + phone: session?.user?.phone || '', category: 'general', message: '', }, diff --git a/web/lib/auth.ts b/web/lib/auth.ts index ff7aa9f..b534a52 100644 --- a/web/lib/auth.ts +++ b/web/lib/auth.ts @@ -8,12 +8,14 @@ import { Routes } from '@/config/routes' declare module 'next-auth' { interface Session { user: { + phone?: string avatar?: string accessToken?: string } & DefaultSession['user'] } interface User { + phone?: string avatar?: string accessToken?: string } @@ -139,6 +141,7 @@ export const authOptions = { token.role = user.role token.accessToken = user.accessToken token.avatar = user.avatar + token.phone = user.phone } return token }, @@ -147,6 +150,7 @@ export const authOptions = { session.user.role = token.role session.user.accessToken = token.accessToken session.user.avatar = token.avatar + session.user.phone = token.phone return session }, }, From d1b311a7c5ba588ba1d1d6d7b06c66d3a128301d Mon Sep 17 00:00:00 2001 From: isra el Date: Thu, 7 Aug 2025 20:33:42 +0300 Subject: [PATCH 2/2] chore(web): remove unused customer-support component --- web/components/shared/customer-support.tsx | 257 --------------------- 1 file changed, 257 deletions(-) delete mode 100644 web/components/shared/customer-support.tsx diff --git a/web/components/shared/customer-support.tsx b/web/components/shared/customer-support.tsx deleted file mode 100644 index 7f94cc0..0000000 --- a/web/components/shared/customer-support.tsx +++ /dev/null @@ -1,257 +0,0 @@ -'use client' - -import { Button } from '@/components/ui/button' -import { - Dialog, - DialogContent, - DialogDescription, - DialogHeader, - DialogTitle, - DialogTrigger, -} from '@/components/ui/dialog' -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from '@/components/ui/form' -import { Input } from '@/components/ui/input' -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from '@/components/ui/select' -import { Textarea } from '@/components/ui/textarea' -import { AlertTriangle, Check, Loader2, MessageSquarePlus } from 'lucide-react' -import { useState } from 'react' -import { useForm } from 'react-hook-form' -import { z } from 'zod' -import { zodResolver } from '@hookform/resolvers/zod' -import { toast } from '@/hooks/use-toast' -import httpBrowserClient from '@/lib/httpBrowserClient' -import { ApiEndpoints } from '@/config/api' - -const SupportFormSchema = z.object({ - name: z.string().min(1, { message: 'Name is required' }), - email: z.string().email({ message: 'Invalid email address' }), - phone: z.string().optional(), - category: z.enum(['general', 'technical', 'billing-and-payments', 'other'], { - message: 'Support category is required', - }), - message: z.string().min(1, { message: 'Message is required' }), -}) - -export default function SupportButton() { - const [open, setOpen] = useState(false) - const [isSubmitting, setIsSubmitting] = useState(false) - const [isSubmitSuccessful, setIsSubmitSuccessful] = useState(false) - const [errorMessage, setErrorMessage] = useState(null) - - const form = useForm({ - resolver: zodResolver(SupportFormSchema), - defaultValues: { - name: '', - email: '', - phone: '', - category: 'general', - message: '', - }, - }) - - const onSubmit = async (data: any) => { - setIsSubmitting(true) - setErrorMessage(null) - - try { - // Use the existing httpBrowserClient to call the NestJS endpoint - const response = await httpBrowserClient.post( - ApiEndpoints.support.customerSupport(), - data - ) - - setIsSubmitSuccessful(true) - - toast({ - title: 'Support request submitted', - description: response.data.message || 'We will get back to you soon.', - }) - - // Wait 3 seconds before closing the dialog - setTimeout(() => { - setOpen(false) - }, 3000) - } catch (error) { - console.error('Error submitting support request:', error) - - setErrorMessage( - 'Error submitting support request. Please try again later.' - ) - - toast({ - title: 'Error submitting support request', - description: 'Please try again later', - variant: 'destructive', - }) - } finally { - setIsSubmitting(false) - } - } - - const onOpenChange = (open: boolean) => { - setOpen(open) - if (!open) { - form.reset() - setIsSubmitSuccessful(false) - setErrorMessage(null) - } - } - - return ( - - - - - - - Contact Support - - Fill out the form below and we'll get back to you as soon as - possible. - - -
- - ( - - Support Category - - - - )} - /> - ( - - Name - - - - - - )} - /> - ( - - Email - - - - - - )} - /> - ( - - Phone (Optional) - - - - - - )} - /> - ( - - Message - -