-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Partner profile updates #2872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Partner profile updates #2872
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
5dc22e6
Add schemas
TWilson023 dd1ba6b
Profile details forms
TWilson023 56a6d80
Remove separate sites page + nav area
TWilson023 4bb43e6
Update schemas
TWilson023 e8d23ac
Merge branch 'main' into partner-profile-updates
TWilson023 909efaa
Merge branch 'main' into partner-profile-updates
TWilson023 512b332
WIP about you section
TWilson023 2bc01fe
WIP industry interests
TWilson023 3e21989
Industry interests
TWilson023 8c89908
Monthly traffic
TWilson023 219c8eb
Update industry-interests-modal.tsx
TWilson023 ec0fdab
"How you work" section
TWilson023 547eeda
Hook things up
TWilson023 d2e51ba
Update `getPartnerForProgram`
TWilson023 6758541
Add new profile fields to enrolled partner page
TWilson023 b004e29
Quick fixes
TWilson023 9449781
Merge branch 'main' into partner-profile-updates
TWilson023 56d1ef5
Fix null/undefined logic
TWilson023 0791798
Replace some `hidden`s with `sr-only`
TWilson023 094ffac
Update update-partner-profile.ts
TWilson023 177b929
Update icons
TWilson023 426a2a8
Update one more icon
TWilson023 246ec97
More tweaks
TWilson023 18991c9
Update update-partner-profile.ts
TWilson023 e1be047
Remove comments
TWilson023 d3093c3
Merge branch 'main' into partner-profile-updates
steven-tey e3c7e8e
Form context fix
TWilson023 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
202 changes: 202 additions & 0 deletions
202
apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/about-you-form.tsx
This file contains hidden or 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,202 @@ | ||
| import { updatePartnerProfileAction } from "@/lib/actions/partners/update-partner-profile"; | ||
| import { | ||
| industryInterests, | ||
| monthlyTrafficAmounts, | ||
| } from "@/lib/partners/partner-profile"; | ||
| import { PartnerProps } from "@/lib/types"; | ||
| import { MAX_PARTNER_DESCRIPTION_LENGTH } from "@/lib/zod/schemas/partners"; | ||
| import { MaxCharactersCounter } from "@/ui/shared/max-characters-counter"; | ||
| import { IndustryInterest, MonthlyTraffic } from "@dub/prisma/client"; | ||
| import { Button, RadioGroup, RadioGroupItem, useEnterSubmit } from "@dub/ui"; | ||
| import { cn } from "@dub/utils"; | ||
| import { useAction } from "next-safe-action/hooks"; | ||
| import { useEffect, useState } from "react"; | ||
| import { Controller, useForm } from "react-hook-form"; | ||
| import ReactTextareaAutosize from "react-textarea-autosize"; | ||
| import { toast } from "sonner"; | ||
| import { IndustryInterestsModal } from "./industry-interests-modal"; | ||
| import { SettingsRow } from "./settings-row"; | ||
|
|
||
| type AboutYouFormData = { | ||
| description: string; | ||
| industryInterests: IndustryInterest[]; | ||
| monthlyTraffic: MonthlyTraffic; | ||
| }; | ||
|
|
||
| export function AboutYouForm({ partner }: { partner?: PartnerProps }) { | ||
| const { | ||
| register, | ||
| control, | ||
| handleSubmit, | ||
| setError, | ||
| getValues, | ||
| reset, | ||
| formState: { errors, isSubmitting, isSubmitSuccessful }, | ||
| } = useForm<AboutYouFormData>({ | ||
| defaultValues: { | ||
| description: partner?.description ?? undefined, | ||
| industryInterests: partner?.industryInterests ?? [], | ||
| monthlyTraffic: partner?.monthlyTraffic ?? undefined, | ||
| }, | ||
| }); | ||
|
|
||
| // Reset form dirty state after submit | ||
| useEffect(() => { | ||
| if (isSubmitSuccessful) | ||
| reset(getValues(), { keepValues: true, keepDirty: false }); | ||
| }, [isSubmitSuccessful, reset, getValues]); | ||
|
|
||
| const { handleKeyDown } = useEnterSubmit(); | ||
|
|
||
| const { executeAsync } = useAction(updatePartnerProfileAction, { | ||
| onSuccess: () => { | ||
| toast.success("Your profile has been updated."); | ||
| }, | ||
| onError({ error }) { | ||
| setError("root.serverError", { | ||
| message: error.serverError, | ||
| }); | ||
|
|
||
| toast.error(error.serverError); | ||
| }, | ||
| }); | ||
|
|
||
| const [showIndustryInterestsModal, setShowIndustryInterestsModal] = | ||
| useState(false); | ||
|
|
||
| return ( | ||
| <div className="border-border-subtle divide-border-subtle flex flex-col divide-y rounded-lg border"> | ||
| <div className="px-6 py-8"> | ||
| <h3 className="text-content-emphasis text-lg font-semibold leading-7"> | ||
| About you and your expertise | ||
| </h3> | ||
| <p className="text-content-subtle text-sm font-normal leading-5"> | ||
| Help programs get to know you, your background, interests, and what | ||
| makes you a great partner. | ||
| </p> | ||
| </div> | ||
|
|
||
| <form | ||
| onSubmit={handleSubmit(async (data) => { | ||
| await executeAsync(data); | ||
| })} | ||
| > | ||
| <SettingsRow | ||
| heading="About you" | ||
| description="Share who you are, what you do, and who your audience is. A strong bio helps you stand out and get accepted into more programs." | ||
| > | ||
| <div> | ||
| <ReactTextareaAutosize | ||
| className={cn( | ||
| "block w-full rounded-md focus:outline-none sm:text-sm", | ||
| errors.description | ||
| ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500" | ||
| : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500", | ||
| )} | ||
| placeholder="Tell us about the kind of content you create – e.g. tech, travel, fashion, etc." | ||
| minRows={3} | ||
| maxRows={10} | ||
| maxLength={MAX_PARTNER_DESCRIPTION_LENGTH} | ||
| onKeyDown={handleKeyDown} | ||
| {...register("description")} | ||
| /> | ||
| <MaxCharactersCounter | ||
| name="description" | ||
| maxLength={MAX_PARTNER_DESCRIPTION_LENGTH} | ||
| control={control} | ||
| /> | ||
| </div> | ||
| </SettingsRow> | ||
|
|
||
| <SettingsRow | ||
| heading="Industry interests" | ||
| description="Add the industries you care and post content about. This helps programs in those areas discover you." | ||
| > | ||
| <Controller | ||
| control={control} | ||
| name="industryInterests" | ||
| render={({ field }) => ( | ||
| <> | ||
| <IndustryInterestsModal | ||
| show={showIndustryInterestsModal} | ||
| setShow={setShowIndustryInterestsModal} | ||
| interests={field.value} | ||
| onSave={(interests) => field.onChange(interests)} | ||
| /> | ||
| <div className="mb-4 flex flex-wrap items-center gap-3"> | ||
| {field.value.length > 0 | ||
| ? industryInterests | ||
| .filter(({ id }) => field.value.includes(id)) | ||
| .map((interest) => ( | ||
| <div | ||
| key={interest.id} | ||
| className={cn( | ||
| "ring-border-subtle flex select-none items-center gap-2.5 rounded-full bg-white px-4 py-3 ring-1", | ||
| )} | ||
| > | ||
| <interest.icon className="size-4 text-neutral-600" /> | ||
| <span className="text-content-emphasis text-sm font-medium"> | ||
| {interest.label} | ||
| </span> | ||
| </div> | ||
| )) | ||
| : [...Array(3)].map((_, idx) => ( | ||
| <div | ||
| key={idx} | ||
| className={cn( | ||
| "border-border-subtle h-11 w-32 rounded-full border border-dashed bg-white", | ||
| )} | ||
| /> | ||
| ))} | ||
| </div> | ||
| <Button | ||
| text={`${field.value.length ? "Edit" : "Add"} interests`} | ||
| onClick={() => setShowIndustryInterestsModal(true)} | ||
| variant="secondary" | ||
| className="h-8 w-fit rounded-lg px-3" | ||
| /> | ||
TWilson023 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </> | ||
| )} | ||
| /> | ||
| </SettingsRow> | ||
|
|
||
| <SettingsRow | ||
| heading="Estimated monthly traffic" | ||
| description="Including websites, newsletters, and social accounts." | ||
| > | ||
| <Controller | ||
| control={control} | ||
| name="monthlyTraffic" | ||
| render={({ field }) => ( | ||
| <RadioGroup | ||
| value={field.value} | ||
| onValueChange={(value) => field.onChange(value)} | ||
| className="flex flex-col gap-4" | ||
| > | ||
| {monthlyTrafficAmounts.map(({ id, label }) => ( | ||
| <label key={id} className="flex items-center gap-2.5"> | ||
| <RadioGroupItem | ||
| value={id} | ||
| className="text-content-emphasis border-border-default" | ||
| /> | ||
| <span className="text-content-emphasis text-sm font-medium"> | ||
| {label} | ||
| </span> | ||
| </label> | ||
| ))} | ||
| </RadioGroup> | ||
| )} | ||
| /> | ||
| </SettingsRow> | ||
|
|
||
| <div className="flex items-center justify-end rounded-b-lg border-t border-neutral-200 bg-neutral-50 px-6 py-4"> | ||
| <Button | ||
| text="Save changes" | ||
| className="h-8 w-fit px-2.5" | ||
| loading={isSubmitting} | ||
| /> | ||
| </div> | ||
| </form> | ||
| </div> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.