Skip to content
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

feature: Unify Thank you pages in a reusable component #140

Merged
merged 14 commits into from
May 9, 2024
94 changes: 94 additions & 0 deletions apps/eo_web/src/components/ThankYou.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { type HTMLAttributes } from "react";
import { Typography } from "@eo/ui";
import { AllDonePanel } from "./AllDonePanel";
import { useMutation } from "@tanstack/react-query";
import axios from "axios";
import { useNavigate, useSearchParams } from "react-router-dom";
import { toast } from "react-toastify";
import { useSurveyStore } from "~/stores/useSurveyStore";
import { Loading } from "~/components/Loading";

import { useMount } from "~/hooks/useMount";
import { useState } from "react";
import { useProfilingStore } from "~/stores/useProfilingStore";

type ThankYouProps = HTMLAttributes<HTMLElement> & {
mutationKey: string;
mutationFunction: (data: object) => Promise<any>;
exitRoute?: string;
isProfiling?: boolean;
}

export const ThankYou = ({ children, mutationKey, mutationFunction, exitRoute = '/', isProfiling = false }: ThankYouProps) => {
const [isLoading, setIsLoading] = useState(true);

const [searchParams] = useSearchParams();

const { email, phase } = useSurveyStore();
const { account, usePayment } = useProfilingStore();

const submission_id = searchParams.get("submission_id") ?? "";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all the submission_id related stuff should be in the parent components, it shouldn't be a responsibility of the ThankYou component.

We should pass it in the mutationKey and mutationParams, and move the navigate to the parent as well.


const navigate = useNavigate();

if (!submission_id) {
navigate(exitRoute);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another approach to early exit & navigate

Suggested change
if (!submission_id) {
navigate(exitRoute);
}
if (!submission_id) {
return <Navigate to={exitRoute} />
}


const { mutate } = useMutation({
mutationFn: mutationFunction,
mutationKey: [mutationKey, submission_id],
onSuccess: () => {
() => setIsLoading(false);
},
onError: (result) => {
if (axios.isAxiosError(result)) {
if (result.response?.status !== 200) {
toast.error("Something went wrong");
}
} else {
toast.error("Something went wrong");
}
},
});

useMount(() => {
if (!isProfiling || usePayment) {

mutate({ email: isProfiling ? account.email : email, phase, submission_id })
};
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of this it would be better to use a prop named mutateOnMount, and just do if (mutateOnMount).

Also, we could pass the mutationParams instead of doing this logic here (which is a bit weird because we are passing the phase from the survey store to the profiling mutation).


return (
<AllDonePanel>
{isLoading ?
<Loading />
: <>
<Typography
variant="base"
font="regular"
className="max-w-xl text-center text-[22px] font-normal leading-[36px]"
>
{children ?? <>
We received your feedback!
<br />
<br />
Thank you!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be passed as a children

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using that as a default because it's shared by 2 out of the 3 pages

</>}
<br />
<br />
Have questions? We’re here. Email support@eo.care, call{" "}
<a href="tel:+1-888-823-6143">888-823-6143</a>, or{" "}
<a
className="cursor-pointer font-new-hero text-[22px] underline"
href="https://calendly.com/eo-care/30min?back=1"
target="_blank"
>
schedule a video chat
</a>{" "}
with a member of our team.
</Typography>
</>}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fragment is unnecessary

</AllDonePanel>
)
};
12 changes: 12 additions & 0 deletions apps/eo_web/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export * from "./AllDonePanel";
export * from "./Carousel";
export * from "./Collapsible";
export * from "./EOInYourInbox";
export * from "./FAQs";
export * from "./Header";
export * from "./HowEOWorks";
export * from "./JotformFrame";
export * from "./Loading";
export * from "./NumberedStep";
export * from "./SurveyResponded";
export * from "./ThankYou";
96 changes: 18 additions & 78 deletions apps/eo_web/src/screens/Cancer/CancerSurveyThankYou.tsx
Original file line number Diff line number Diff line change
@@ -1,97 +1,37 @@
import { useState } from "react";
import { useMutation } from "@tanstack/react-query";
import axios from "axios";
import { useNavigate, useSearchParams } from "react-router-dom";
import { toast } from "react-toastify";

import { Typography } from "@eo/ui";

import { useApi } from "~/api/useApi";
import { AllDonePanel } from "~/components/AllDonePanel";
import { FAQs } from "~/components/FAQs";
import { HowEOWorks } from "~/components/HowEOWorks";
import { Loading } from "~/components/Loading";
import { useMount } from "~/hooks/useMount";
import { LayoutDefault } from "~/layouts";
import { FooterFull } from "~/layouts/FooterFull";
import { Flows } from "~/stores/useProfilingStore";
import { useSurveyStore } from "~/stores/useSurveyStore";
import { Flows, type FlowType } from "~/stores/useProfilingStore";
import { Footer } from "~/layouts/Footer";
import { ThankYou } from "~/components";
import { useSurveyStore } from "~/stores/useSurveyStore";
import { useApi } from "~/api/useApi";

const flowsWithSmallFooter: FlowType[] = [
Flows.c_org,
Flows.cancer_pilot,
Flows.twist_out_cancer,
Flows.cancer_support_community,
Flows.resource_center_1,
Flows.resource_center_2,
Flows.employer_center,
Flows.inova,
];

export const CancerSurveyThankYou = () => {
const [isLoading, setIsLoading] = useState(true);

const [searchParams] = useSearchParams();

const { email, phase, flow } = useSurveyStore();

const submission_id = searchParams.get("submission_id") ?? "";

const navigate = useNavigate();

if (!submission_id) {
navigate("/");
}
const { flow } = useSurveyStore();

const { postCancerSurveyFormSubmission } = useApi();

const { mutate } = useMutation({
mutationFn: postCancerSurveyFormSubmission,
mutationKey: ["postCancerSurveyFormSubmission", submission_id],
onSuccess: () => {
setIsLoading(false);
},
onError: (result) => {
if (axios.isAxiosError(result)) {
if (result.response?.status !== 200) {
toast.error("Something went wrong");
}
} else {
toast.error("Something went wrong");
}
},
});

useMount(() => mutate({ email, phase, submission_id }));

if (isLoading) {
return (
<LayoutDefault>
<Loading />
</LayoutDefault>
);
}

return (
<LayoutDefault>
<AllDonePanel>
<Typography
variant="base"
font="regular"
className="max-w-xl text-center text-[22px] font-normal leading-[36px]"
>
We received your feedback! <br />
<br />
Thank you! <br />
<br />
Have questions? We’re here. Email support@eo.care, call{" "}
<a href="tel:+1-888-823-6143">888-823-6143</a>, or{" "}
<a
className="cursor-pointer font-new-hero text-[22px] underline"
href="https://calendly.com/eo-care/30min?back=1"
target="_blank"
>
schedule a video chat
</a>{" "}
with a member of our team.
</Typography>
</AllDonePanel>
<ThankYou mutationKey="postCancerSurveyFormSubmission" mutationFunction={postCancerSurveyFormSubmission} />
<HowEOWorks pilot={flow === Flows.cancer_pilot} />
<FAQs flow={flow} />
{['c_org', 'cancer_pilot', 'twist_out_cancer', 'cancer_support_community', 'employer_center', 'resource_center_1', 'resource_center_2', 'inova'].includes(flow)
{flowsWithSmallFooter.includes(flow)
? <Footer flow={flow} />
: <FooterFull />}
</LayoutDefault>
</LayoutDefault >
);
};
76 changes: 11 additions & 65 deletions apps/eo_web/src/screens/ProfilingThankYou.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import React from "react";
import { useMutation } from "@tanstack/react-query";
import axios from "axios";
import { useNavigate, useSearchParams } from "react-router-dom";
import { toast } from "react-toastify";

import { Typography } from "@eo/ui";

import { useApi } from "~/api/useApi";
import { AllDonePanel } from "~/components/AllDonePanel";
import { ThankYou } from "~/components";
import { EOInYourInbox } from "~/components/EOInYourInbox";
import { FAQs } from "~/components/FAQs";
import { HowEOWorks } from "~/components/HowEOWorks";
import { WEB_APP_URL } from "~/configs/env";
import { useMount } from "~/hooks/useMount";
import { LayoutDefault } from "~/layouts";
import { Footer } from "~/layouts/Footer";
import { FooterFull } from "~/layouts/FooterFull";
Expand All @@ -38,72 +31,25 @@ const flowsWithSmallFooter: FlowType[] = [
];

export const ProfilingThankYou = () => {
const [searchParams] = useSearchParams();
const { account, flow, usePayment } = useProfilingStore();
const submissionId = searchParams.get("submission_id") || "";
const navigate = useNavigate();

if (!submissionId) {
navigate(ROUTES.userRolSelector);
}
const { flow } = useProfilingStore();

const { checkoutComplete } = useApi();

const { mutate } = useMutation({
mutationFn: checkoutComplete,
mutationKey: ["checkoutComplete", submissionId],
onError: (result) => {
if (axios.isAxiosError(result)) {
if (result.response?.status !== 200) {
toast.error("Something went wrong");
}
} else {
toast.error("Something went wrong");
}
},
});

useMount(() => {
if (usePayment) {
mutate({
email: account.email,
submission_id: submissionId,
});
}
});

const goToWebApp = () => {
window.location.href = WEB_APP_URL;
};

return (
<LayoutDefault>
<AllDonePanel>
<Typography
variant="base"
font="regular"
className="max-w-3xl text-center text-[22px] font-normal leading-[36px]"
>
You’ll be able to review your initial, personalized,
clinician-approved care plan within 24 hours. When your care plan is
ready, we will send you an email with a link to{" "}
<span className="cursor-pointer underline" onClick={goToWebApp}>
log into your account.
</span>
<br />
<br />
Have questions? We’re here. Email support@eo.care, call{" "}
<a href="tel:+1-888-823-6143">888-823-6143</a>, or{" "}
<a
className="cursor-pointer font-new-hero text-[22px] underline"
href="https://calendly.com/eo-care/30min?back=1"
target="_blank"
>
schedule a video chat
</a>{" "}
with a member of our team.
</Typography>
</AllDonePanel>
<ThankYou mutationKey="checkoutComplete" mutationFunction={checkoutComplete} isProfiling={true} exitRoute={ROUTES.userRolSelector}>
You’ll be able to review your initial, personalized,
clinician-approved care plan within 24 hours. When your care plan is
ready, we will send you an email with a link to{" "}
<span className="cursor-pointer underline" onClick={goToWebApp}>
log into your account.
</span>
</ThankYou>

<HowEOWorks pilot={flow == Flows.cancer_pilot} />
<FAQs flow={flow} />
<EOInYourInbox />
Expand Down
Loading
Loading