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