Skip to content

Commit

Permalink
feat: add referred by question (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgoycoechea-lightit authored Jul 24, 2024
1 parent a98fd86 commit 4c84836
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
1 change: 1 addition & 0 deletions apps/eo_web/src/api/useApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ interface CreatePreProfileParams {
email: string;
phone_number: string;
origin: string;
referred_by: string;
}

export const useApi = () => {
Expand Down
38 changes: 35 additions & 3 deletions apps/eo_web/src/screens/AccountCreation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@ import {
type FlowType,
} from "~/stores/useProfilingStore";

export const ReferralOptions = {
"Twist Out Cancer": Flows.twist_out_cancer,
"Unite for Her": Flows.unite_for_her,
"Imerman Angels": Flows.imerman,
"Stupid Cancer": Flows.stupid_cancer,
"Cancer Support Community": Flows.cancer_support_community,
"UVA": Flows.uva,
"Inova": Flows.inova,
} as const;

export type ReferralOptionsType = keyof typeof ReferralOptions;

const getFlowFromReferral = (value: string) => {
const keys = Object.keys(ReferralOptions) as ReferralOptionsType[]
const key = keys.find(key => key === value)
return key ? ReferralOptions[key] : undefined
}

const getReferredBy = (searchParams: URLSearchParams) => {
const encodedReferredBy = searchParams.get("referred_by") ?? undefined
return encodedReferredBy ? decodeURIComponent(encodedReferredBy) : undefined
}


export const signUpSchema = z.object({
// Profiling
firstName: z.string().min(1, { message: "First name is required" }),
Expand Down Expand Up @@ -66,6 +90,7 @@ export type SignUpFormSchema = z.infer<typeof signUpSchema>;

export const AccountCreation = () => {
const navigate = useNavigate();

const [useParams] = useSearchParams();
const {
account,
Expand All @@ -75,8 +100,12 @@ export const AccountCreation = () => {
setState,
setExperience,
flow,
setReferredBy,
} = useProfilingStore((state) => state);

const referredBy = getReferredBy(useParams)
const referredFlow = referredBy ? getFlowFromReferral(referredBy) : undefined

const [validatingForm, setValidatingForm] = useState(false);
const { mutate: createPreProfile } = usePreProfile().preProfileMutation;
const {
Expand Down Expand Up @@ -109,7 +138,8 @@ export const AccountCreation = () => {
last_name: data.lastName,
email: data.email,
phone_number: data.phoneNumber.replace(/\D/g, ""),
origin: getIndex(flow),
origin: referredFlow ? getIndex(referredFlow) : getIndex(flow),
referred_by: referredBy ?? "",
});
switch (channel) {
case "cancer":
Expand Down Expand Up @@ -166,6 +196,7 @@ export const AccountCreation = () => {
const submissionId = useParams.get("submission_id");
const state = useParams.get("state");
const experience = useParams.get("experience") ?? "";
const referredBy = getReferredBy(useParams) ?? "";

if (!submissionId) {
toast.error(
Expand All @@ -178,6 +209,7 @@ export const AccountCreation = () => {
setState(state);
setIntroQuestionSubmissionId(submissionId);
setExperience(experience);
setReferredBy(referredBy);
}
});

Expand Down Expand Up @@ -260,7 +292,7 @@ export const AccountCreation = () => {
className={tw(
"font-nunito text-[11px] font-light ",
errors.agreeReceiveNotifications?.message &&
"text-red-500",
"text-red-500",
)}
>
I agree to receive emails and text messages related to my
Expand All @@ -282,7 +314,7 @@ export const AccountCreation = () => {
className={tw(
"font-nunito text-[11px] font-light !leading-4",
errors.agreeTermsAndConditions?.message &&
"text-red-500",
"text-red-500",
)}
>
I have read and agree to the{" "}
Expand Down
3 changes: 2 additions & 1 deletion apps/eo_web/src/screens/Checkout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const Checkout = () => {
const { usePayment } = useProfilingStore();
const [searchParams] = useSearchParams();

const { account, introQuestionSubmissionId, channel, flow, origin } =
const { account, introQuestionSubmissionId, channel, flow, origin, referredBy } =
useProfilingStore();

const formParams = new URLSearchParams({
Expand Down Expand Up @@ -80,6 +80,7 @@ export const Checkout = () => {
agree_terms_and_conditions: account.agreeTermsAndConditions,
channel,
flow,
referredBy,
}),
);

Expand Down
3 changes: 2 additions & 1 deletion apps/eo_web/src/screens/ProfilingIntroQuestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import { useProfilingStore } from "~/stores/useProfilingStore";

export const ProfilingIntroQuestions = () => {
const navigate = useNavigate();
const { channel, type, origin } = useProfilingStore((state) => state);
const { channel, type, origin, flow } = useProfilingStore((state) => state);
const searchParams = new URLSearchParams({
origin,
flow
});

let introQuestionsId: string | number | null = null;
Expand Down
6 changes: 6 additions & 0 deletions apps/eo_web/src/stores/useProfilingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface ProfilingStore {
experience: string;
account: Account;
flow: FlowType;
referredBy: string;
setAccountData: (account: Account) => void;
setChannel: (channel: Channel) => void;
setType: (type: Type) => void;
Expand All @@ -60,6 +61,7 @@ export interface ProfilingStore {
setOrigin: (origin: string) => void;
setExperience: (experience: string) => void;
setFlow: (flow: FlowType) => void;
setReferredBy: (referredBy: string) => void;
}

const defaultState = {
Expand All @@ -81,6 +83,7 @@ const defaultState = {
},
usePayment: true,
flow: Flows.marketing_site,
referredBy: "",
};

export const useProfilingStore = create<ProfilingStore>()(
Expand Down Expand Up @@ -119,6 +122,9 @@ export const useProfilingStore = create<ProfilingStore>()(
setFlow: (flow: FlowType) => {
set({ flow });
},
setReferredBy: (referredBy: string) => {
set({ referredBy });
},
...defaultState,
}),
{
Expand Down
2 changes: 2 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
"iconify",
"imerman",
"inova",
"intoxi",
"jotform",
"LARAVEL",
"manypkg",
"medtech",
"middlewares",
"nonworkday",
"NEXTAUTH",
"pnpm",
"rgba",
Expand Down

0 comments on commit 4c84836

Please sign in to comment.