-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add email address to feedback form (#574)
- Loading branch information
1 parent
0161d35
commit f494008
Showing
9 changed files
with
160 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.fern-checkbox-label { | ||
@apply flex cursor-pointer; | ||
} | ||
|
||
.fern-checkbox-item { | ||
@apply ring-default relative mt-0.5 inline-block size-4 ring-1 rounded-sm ring-inset; | ||
} | ||
|
||
.fern-checkbox-item:hover { | ||
@apply bg-tag-primary; | ||
} | ||
|
||
.fern-checkbox-item:focus { | ||
@apply outline outline-4 outline-offset-0 outline-tag-primary; | ||
} | ||
|
||
.fern-checkbox-indicator { | ||
@apply size-4 bg-accent flex items-center justify-center text-accent-primary-contrast rounded-sm; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as Checkbox from "@radix-ui/react-checkbox"; | ||
import { CheckIcon } from "@radix-ui/react-icons"; | ||
import cn from "clsx"; | ||
import { FC, ReactNode } from "react"; | ||
import "./FernCheckbox.css"; | ||
|
||
interface FernCheckboxProps extends Checkbox.CheckboxProps { | ||
labelClassName?: string; | ||
label?: ReactNode; | ||
helperText?: ReactNode; | ||
compact?: boolean; | ||
} | ||
|
||
export const FernCheckbox: FC<FernCheckboxProps> = ({ | ||
labelClassName, | ||
label, | ||
helperText, | ||
children, | ||
className, | ||
compact, | ||
...props | ||
}) => ( | ||
<label className={cn("fern-checkbox-label", { compact })}> | ||
<Checkbox.Root className="fern-checkbox-item" {...props}> | ||
<Checkbox.Indicator className="fern-checkbox-indicator"> | ||
<CheckIcon /> | ||
</Checkbox.Indicator> | ||
</Checkbox.Root> | ||
|
||
<div className="ml-2 flex-1"> | ||
<div className={cn("text-sm font-semibold", labelClassName)}>{label}</div> | ||
{helperText && <p className="t-muted mb-0 text-xs">{helperText}</p>} | ||
{children} | ||
</div> | ||
</label> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,33 @@ | ||
import { useKeyboardPress } from "@fern-ui/react-commons"; | ||
import { useAtom } from "jotai"; | ||
import { atomWithStorage } from "jotai/utils"; | ||
import { FC, useCallback, useMemo, useRef, useState } from "react"; | ||
import { FernButton } from "../components/FernButton"; | ||
import { FernCheckbox } from "../components/FernCheckbox"; | ||
import { FernDropdown } from "../components/FernDropdown"; | ||
import { FernInput } from "../components/FernInput"; | ||
import { FernRadioGroup } from "../components/FernRadioGroup"; | ||
import { FernTextarea } from "../components/FernTextarea"; | ||
|
||
interface FeedbackFormProps { | ||
feedback: "yes" | "no" | undefined; | ||
onSubmit: (feedbackId: string, message: string) => void; | ||
onSubmit: (feedback: { | ||
feedbackId: string; | ||
feedbackMessage: string; | ||
email: string; | ||
showEmailInput: boolean | "indeterminate"; | ||
}) => void; | ||
} | ||
|
||
const SHOW_EMAIL_INPUT_ATOM = atomWithStorage<boolean | "indeterminate">("feedback-show-email-input", false); | ||
const EMAIL_ATOM = atomWithStorage<string>("feedback-email", ""); | ||
|
||
export const FeedbackForm: FC<FeedbackFormProps> = ({ feedback, onSubmit }) => { | ||
const textareaRef = useRef<HTMLTextAreaElement>(null); | ||
const [feedbackId, setFeedbackId] = useState<string>(); | ||
const [feedbackMessage, setFeedbackMessage] = useState<string>(""); | ||
const [showEmailInput, setShowEmailInput] = useAtom(SHOW_EMAIL_INPUT_ATOM); | ||
const [email, setEmail] = useAtom(EMAIL_ATOM); | ||
|
||
const legend = feedback === "yes" ? "What did you like?" : feedback === "no" ? "What went wrong?" : "Feedback"; | ||
const feedbackOptions = useMemo<FernDropdown.Option[]>(() => { | ||
|
@@ -28,7 +42,7 @@ export const FeedbackForm: FC<FeedbackFormProps> = ({ feedback, onSubmit }) => { | |
active ? ( | ||
<FernTextarea | ||
ref={textareaRef} | ||
autoFocus={true} | ||
// autoFocus={true} | ||
className="mt-2 w-full" | ||
placeholder="(Optional) Tell us more about your experience" | ||
onValueChange={setFeedbackMessage} | ||
|
@@ -74,7 +88,12 @@ export const FeedbackForm: FC<FeedbackFormProps> = ({ feedback, onSubmit }) => { | |
if (feedbackId == null) { | ||
return; | ||
} | ||
onSubmit(feedbackId, feedbackMessage); | ||
onSubmit({ | ||
feedbackId, | ||
feedbackMessage, | ||
email, | ||
showEmailInput, | ||
}); | ||
}; | ||
|
||
return ( | ||
|
@@ -87,6 +106,7 @@ export const FeedbackForm: FC<FeedbackFormProps> = ({ feedback, onSubmit }) => { | |
value={feedbackId} | ||
onValueChange={setFeedbackId} | ||
options={feedbackOptions} | ||
autoFocus={true} | ||
/> | ||
) : ( | ||
<FernTextarea | ||
|
@@ -98,6 +118,27 @@ export const FeedbackForm: FC<FeedbackFormProps> = ({ feedback, onSubmit }) => { | |
/> | ||
)} | ||
|
||
<hr className="border-border-concealed my-4" /> | ||
|
||
<div className="mt-4"> | ||
<FernCheckbox | ||
label="Yes, it's okay to follow up by email." | ||
checked={showEmailInput} | ||
onCheckedChange={setShowEmailInput} | ||
autoFocus={false} | ||
> | ||
{showEmailInput && ( | ||
<FernInput | ||
className="mt-2" | ||
type="email" | ||
placeholder="[email protected]" | ||
value={email} | ||
onValueChange={setEmail} | ||
/> | ||
)} | ||
</FernCheckbox> | ||
</div> | ||
|
||
<FernButton | ||
full={true} | ||
intent="primary" | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.