Files
community-rule/app/components/modals/AskOrganizerInquiry/AskOrganizerInquiryModal.view.tsx
T

168 lines
4.7 KiB
TypeScript

"use client";
import Link from "next/link";
import Create from "../Create";
import TextInput from "../../controls/TextInput";
import TextArea from "../../controls/TextArea";
import Button from "../../buttons/Button";
import Alert from "../Alert";
import {
ASK_ORGANIZER_INQUIRY_FORM_ID,
ORGANIZER_INQUIRY_HONEYPOT_FIELD,
} from "../../../../lib/organizerInquiryConstants";
import type { AskOrganizerInquiryModalViewProps } from "./AskOrganizerInquiryModal.types";
/**
* Figma: Overlay / Modal / Ask an Organizer (22078:587823)
* Sent 25032:48584, send failed 25032:48642
*/
export function AskOrganizerInquiryModalView({
isOpen,
onClose,
copy,
email,
message,
honeypot,
submitting,
success,
sendFailed,
emailError,
questionError,
onEmailChange,
onMessageChange,
onHoneypotChange,
onSubmit,
onDismissFailed,
}: AskOrganizerInquiryModalViewProps) {
const failedToast = sendFailed ? (
<Alert
type="toast"
status="danger"
size="s"
title={copy.sendFailedTitle}
description={copy.sendFailedDescription}
hasLeadingIcon
hasBodyText
hasTrailingIcon={false}
onClose={onDismissFailed}
className="w-full"
/>
) : null;
const footer = (
<div className="flex w-full flex-col gap-4 px-1">
<div className="md:hidden">{failedToast}</div>
{success ? (
<Button
type="button"
buttonType="filled"
palette="default"
size="large"
className="w-full !justify-center"
autoFocus
onClick={onClose}
>
{copy.closeAfterSuccess}
</Button>
) : (
<Button
type="submit"
form={ASK_ORGANIZER_INQUIRY_FORM_ID}
buttonType="filled"
palette="default"
size="large"
className="w-full !justify-center"
disabled={submitting}
>
{copy.submitButton}
</Button>
)}
</div>
);
return (
<Create
isOpen={isOpen}
onClose={onClose}
presentation="sheet"
backdropVariant="blurredYellow"
title={success ? copy.successTitle : copy.title}
description={success ? copy.successDescription : copy.description}
showBackButton={false}
showNextButton={false}
stepper={false}
ariaLabel={copy.ariaDialog}
footerContent={footer}
footerClassName="!h-auto min-h-[112px] shrink-0 flex flex-col justify-end pb-8 pt-3 px-4"
belowCard={
success ? undefined : (
<div className="flex w-full max-w-[546px] flex-col items-center gap-6">
<div className="hidden w-full md:block">{failedToast}</div>
<Link
href="/"
className="text-small-paragraph text-[var(--color-content-invert-tertiary,#2d2d2d)] text-center hover:opacity-90"
onClick={() => onClose()}
>
{copy.backToHome}
</Link>
</div>
)
}
>
{success ? null : (
<form
id={ASK_ORGANIZER_INQUIRY_FORM_ID}
className="relative flex flex-col gap-6 pb-2"
onSubmit={onSubmit}
noValidate
>
<TextInput
type="email"
name="email"
autoComplete="email"
label={copy.emailLabel}
placeholder={copy.emailPlaceholder}
value={email}
onChange={(e) => onEmailChange(e.target.value)}
error={emailError}
textHint={emailError ? copy.emailInvalid : false}
inputSize="medium"
showHelpIcon={false}
/>
<TextArea
name="message"
label={copy.questionLabel}
placeholder={copy.questionPlaceholder}
value={message}
onChange={(e) => onMessageChange(e.target.value)}
error={questionError}
textHint={questionError ? copy.questionTooShort : false}
size="medium"
appearance="embedded"
rows={4}
/>
<div
aria-hidden="true"
className="pointer-events-none absolute left-0 top-0 h-px w-px overflow-hidden opacity-0"
>
<label htmlFor={`${ASK_ORGANIZER_INQUIRY_FORM_ID}-${ORGANIZER_INQUIRY_HONEYPOT_FIELD}`}>
{copy.honeypotLabel}
</label>
<input
id={`${ASK_ORGANIZER_INQUIRY_FORM_ID}-${ORGANIZER_INQUIRY_HONEYPOT_FIELD}`}
type="text"
name={ORGANIZER_INQUIRY_HONEYPOT_FIELD}
tabIndex={-1}
autoComplete="off"
value={honeypot}
onChange={(e) => onHoneypotChange(e.target.value)}
/>
</div>
</form>
)}
</Create>
);
}