-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement referral source for onboarding
- Loading branch information
1 parent
34bd366
commit 8c9d2b2
Showing
9 changed files
with
162 additions
and
53 deletions.
There are no files selected for viewing
43 changes: 0 additions & 43 deletions
43
packages/components/src/registration/onboarding/DiscoveryDropdown.tsx
This file was deleted.
Oops, something went wrong.
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
74 changes: 74 additions & 0 deletions
74
packages/components/src/registration/onboarding/ReferralDropdown.tsx
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,74 @@ | ||
import { useState } from "react"; | ||
import { Controller, useFormContext } from "react-hook-form"; | ||
|
||
import { ReferralSource } from "@good-dog/db"; | ||
import { | ||
Select, | ||
SelectContent, | ||
SelectGroup, | ||
SelectItem, | ||
SelectTrigger, | ||
SelectValue, | ||
} from "@good-dog/ui/select"; | ||
|
||
export default function ReferralDropdown() { | ||
const { control, register } = useFormContext<{ | ||
source?: string; | ||
customSource?: string; | ||
}>(); | ||
|
||
const referralOptions = Object.values(ReferralSource); | ||
|
||
const [isOtherSelected, setIsOtherSelected] = useState(false); | ||
|
||
const handleSelectChange = (value: string) => { | ||
setIsOtherSelected(value === "OTHER"); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h3 className="mb-3 mt-4">How did you hear about Good Dog?</h3> | ||
<Controller | ||
name="source" | ||
control={control} | ||
render={({ field }) => ( | ||
<Select | ||
{...field} | ||
onValueChange={(value: string) => { | ||
field.onChange(value); | ||
handleSelectChange(value); | ||
}} | ||
> | ||
<SelectTrigger className="border-black bg-white"> | ||
<SelectValue placeholder="Select" /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
<SelectGroup> | ||
{referralOptions.map((option) => ( | ||
<SelectItem key={option} value={option}> | ||
{option} | ||
</SelectItem> | ||
))} | ||
</SelectGroup> | ||
</SelectContent> | ||
</Select> | ||
)} | ||
/> | ||
|
||
{isOtherSelected && ( | ||
<div className="mt-4"> | ||
<label htmlFor="customSource" className="mb-2 block"> | ||
Please specify: | ||
</label> | ||
<input | ||
id="customSource" | ||
{...register("customSource")} | ||
type="text" | ||
placeholder="Enter details" | ||
className="w-full border border-black p-2" | ||
/> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/db/prisma/migrations/20250119220136_added_referral_source/migration.sql
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,20 @@ | ||
-- CreateEnum | ||
CREATE TYPE "ReferralSource" AS ENUM ('FRIEND', 'COLLEAGUE', 'GREEN_LINE_RECORDS', 'SOCIAL_MEDIA', 'OTHER'); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Referral" ( | ||
"id" TEXT NOT NULL, | ||
"userId" TEXT NOT NULL, | ||
"source" "ReferralSource" NOT NULL, | ||
"customSource" TEXT, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "Referral_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Referral_userId_key" ON "Referral"("userId"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Referral" ADD CONSTRAINT "Referral_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
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,3 +1,6 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
import { PrismaClient, ReferralSource } from "@prisma/client"; | ||
|
||
export const prisma = new PrismaClient(); | ||
|
||
export { ReferralSource }; | ||
export type ReferralType = keyof typeof ReferralSource; |
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