fix(signup): when signing up for the event and already logged in, set the email of the account
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
import {
|
||||
inputCls,
|
||||
validateEmail,
|
||||
@@ -25,6 +26,9 @@ interface Props {
|
||||
}
|
||||
|
||||
export function PerformerForm({ onBack, onSuccess }: Props) {
|
||||
const { data: session } = authClient.useSession();
|
||||
const sessionEmail = session?.user?.email ?? "";
|
||||
|
||||
const [data, setData] = useState({
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
@@ -39,6 +43,12 @@ export function PerformerForm({ onBack, onSuccess }: Props) {
|
||||
const [errors, setErrors] = useState<PerformerErrors>({});
|
||||
const [touched, setTouched] = useState<Record<string, boolean>>({});
|
||||
|
||||
useEffect(() => {
|
||||
if (sessionEmail) {
|
||||
setData((prev) => ({ ...prev, email: sessionEmail }));
|
||||
}
|
||||
}, [sessionEmail]);
|
||||
|
||||
const submitMutation = useMutation({
|
||||
...orpc.submitRegistration.mutationOptions(),
|
||||
onSuccess: (result) => {
|
||||
@@ -254,14 +264,15 @@ export function PerformerForm({ onBack, onSuccess }: Props) {
|
||||
id="p-email"
|
||||
name="email"
|
||||
value={data.email}
|
||||
onChange={handleChange}
|
||||
onBlur={handleBlur}
|
||||
onChange={sessionEmail ? undefined : handleChange}
|
||||
onBlur={sessionEmail ? undefined : handleBlur}
|
||||
readOnly={!!sessionEmail}
|
||||
placeholder="jouw@email.be"
|
||||
autoComplete="email"
|
||||
inputMode="email"
|
||||
aria-required="true"
|
||||
aria-invalid={touched.email && !!errors.email}
|
||||
className={inputCls(!!touched.email && !!errors.email)}
|
||||
className={`${inputCls(!!touched.email && !!errors.email)}${sessionEmail ? "cursor-not-allowed opacity-75" : ""}`}
|
||||
/>
|
||||
{touched.email && errors.email && (
|
||||
<span className="text-red-300 text-sm" role="alert">
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
import {
|
||||
calculateDrinkCard,
|
||||
type GuestEntry,
|
||||
@@ -30,6 +31,9 @@ interface Props {
|
||||
// ── Main watcher form ──────────────────────────────────────────────────────
|
||||
|
||||
export function WatcherForm({ onBack, onSuccess }: Props) {
|
||||
const { data: session } = authClient.useSession();
|
||||
const sessionEmail = session?.user?.email ?? "";
|
||||
|
||||
const [data, setData] = useState({
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
@@ -43,6 +47,12 @@ export function WatcherForm({ onBack, onSuccess }: Props) {
|
||||
const [guestErrors, setGuestErrors] = useState<GuestErrors[]>([]);
|
||||
const [giftAmount, setGiftAmount] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (sessionEmail) {
|
||||
setData((prev) => ({ ...prev, email: sessionEmail }));
|
||||
}
|
||||
}, [sessionEmail]);
|
||||
|
||||
const submitMutation = useMutation({
|
||||
...orpc.submitRegistration.mutationOptions(),
|
||||
onSuccess: (result) => {
|
||||
@@ -290,14 +300,15 @@ export function WatcherForm({ onBack, onSuccess }: Props) {
|
||||
id="w-email"
|
||||
name="email"
|
||||
value={data.email}
|
||||
onChange={handleChange}
|
||||
onBlur={handleBlur}
|
||||
onChange={sessionEmail ? undefined : handleChange}
|
||||
onBlur={sessionEmail ? undefined : handleBlur}
|
||||
readOnly={!!sessionEmail}
|
||||
placeholder="jouw@email.be"
|
||||
autoComplete="email"
|
||||
inputMode="email"
|
||||
aria-required="true"
|
||||
aria-invalid={touched.email && !!errors.email}
|
||||
className={inputCls(!!touched.email && !!errors.email)}
|
||||
className={`${inputCls(!!touched.email && !!errors.email)}${sessionEmail ? "cursor-not-allowed opacity-75" : ""}`}
|
||||
/>
|
||||
{touched.email && errors.email && (
|
||||
<span className="text-red-300 text-sm" role="alert">
|
||||
|
||||
Reference in New Issue
Block a user