Openstatus www.openstatus.dev

feat: prefill contact form (#860)

authored by

Maximilian Kaske and committed by
GitHub
22fca23f 39b00b09

+16 -5
+4 -2
apps/web/src/app/app/layout.tsx
··· 12 12 return ( 13 13 <PHProvider> 14 14 <PostHogPageview /> 15 - <SessionProvider>{children}</SessionProvider> 16 - <Bubble /> 15 + <SessionProvider> 16 + {children} 17 + <Bubble /> 18 + </SessionProvider> 17 19 </PHProvider> 18 20 ); 19 21 }
+11 -2
apps/web/src/components/support/bubble.tsx
··· 11 11 } from "@openstatus/ui"; 12 12 13 13 import { ContactForm } from "./contact-form"; 14 + import { useSession } from "next-auth/react"; 14 15 15 16 export function Bubble() { 16 17 const [open, setOpen] = useState(false); 17 18 const [formVisible, setFormVisible] = useState(false); 19 + const session = useSession(); 18 20 19 21 return ( 20 22 <div className="fixed right-4 bottom-4 z-50 rounded-full bg-background"> 21 23 <Popover 22 24 open={open} 23 25 onOpenChange={(value) => { 24 - // TODO: improve as if you do it quickly, it will still be visible and jump 25 26 if (formVisible && !value) { 26 27 setTimeout(() => setFormVisible(false), 300); // reset form after popover closes 27 28 } ··· 76 77 </Button> 77 78 </div> 78 79 ) : ( 79 - <ContactForm onSubmit={() => setOpen(false)} /> 80 + <ContactForm 81 + defaultValues={{ 82 + name: 83 + session?.data?.user?.name || 84 + `${session?.data?.user?.firstName} ${session?.data?.user?.lastName}`, 85 + email: session?.data?.user?.email ?? undefined, 86 + }} 87 + onSubmit={() => setOpen(false)} 88 + /> 80 89 )} 81 90 </PopoverContent> 82 91 </Popover>
+1 -1
apps/web/src/components/support/contact-form.tsx
··· 61 61 export type FormValues = z.infer<typeof FormSchema>; 62 62 63 63 interface ContactFormProps { 64 - defaultValues?: FormValues; 64 + defaultValues?: Partial<FormValues>; 65 65 onSubmit?: () => void; 66 66 } 67 67