Skip to content

Commit

Permalink
[CU-86dtub3qj] pre profile (#180)
Browse files Browse the repository at this point in the history
* feat: implement pre-profile

* feat: improve the createPreProfile implementing interface
  • Loading branch information
cgarcia-lightit authored Jun 19, 2024
1 parent 7a32b25 commit 6affdfc
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 145 deletions.
1 change: 1 addition & 0 deletions apps/eo_web/dist/assets/main-17ed8018.css

Large diffs are not rendered by default.

121 changes: 0 additions & 121 deletions apps/eo_web/dist/assets/main-1935110a.js

This file was deleted.

120 changes: 120 additions & 0 deletions apps/eo_web/dist/assets/main-33e11077.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion apps/eo_web/dist/assets/main-a73a2c36.css

This file was deleted.

6 changes: 3 additions & 3 deletions apps/eo_web/dist/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
"src": "../../packages/ui/src/assets/avatar.svg"
},
"src/main.css": {
"file": "assets/main-a73a2c36.css",
"file": "assets/main-17ed8018.css",
"src": "src/main.css"
},
"src/main.tsx": {
"assets": [
"assets/UploadFile-694e44b5.svg"
],
"css": [
"assets/main-a73a2c36.css"
"assets/main-17ed8018.css"
],
"file": "assets/main-1935110a.js",
"file": "assets/main-33e11077.js",
"isEntry": true,
"src": "src/main.tsx"
}
Expand Down
13 changes: 12 additions & 1 deletion apps/eo_web/src/api/useApi.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { apiElixir, apiLaravel } from "~/api/axios";
import {
type AvoidPresentation,
type Maladies,
Expand All @@ -6,7 +7,6 @@ import {
type ThcProductPreferences,
type WorseSymptomsMoment,
} from "~/api/PrePlanTypes";
import { apiElixir, apiLaravel } from "~/api/axios";
import { useProfileStore, type Profile } from "~/stores/useProfileStore";
import { type FlowType } from "~/stores/useProfilingStore";

Expand Down Expand Up @@ -74,6 +74,13 @@ export interface ProfileOne {
};
}

interface CreatePreProfileParams {
first_name: string;
last_name: string;
email: string;
phone_number: string;
}

export const useApi = () => {
const token = useProfileStore((state) => state.session?.token);

Expand Down Expand Up @@ -171,6 +178,9 @@ export const useApi = () => {
const checkoutComplete = async (data: object) =>
await apiLaravel.patch("/api/profiles/checkout-complete", data);

const createPreProfile = (data: CreatePreProfileParams) =>
apiLaravel.post<LaravelSuccessBase<void>>("api/pre-profiling", data);

return {
validateZipCode,
combineProfileOne,
Expand All @@ -188,5 +198,6 @@ export const useApi = () => {
surveyStatus,
getProfilingFlow,
checkoutComplete,
createPreProfile,
};
};
16 changes: 16 additions & 0 deletions apps/eo_web/src/api/usePreProfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useMutation } from "@tanstack/react-query";

import { useApi } from "~/api/useApi";

export const usePreProfile = () => {
const { createPreProfile } = useApi();

const preProfileMutation = useMutation({
mutationFn: createPreProfile,
mutationKey: ["createPreProfile"],
});

return {
preProfileMutation,
};
};
46 changes: 27 additions & 19 deletions apps/eo_web/src/screens/AccountCreation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { toast } from "react-toastify";
import { z } from "zod";

import { tw } from "@eo/shared/src";
import { Button, Input, Typography, icons } from "@eo/ui";
import { Button, icons, Input, Typography } from "@eo/ui";
import { CheckBox } from "@eo/ui/src/form/CheckBox";

import { useApi } from "~/api/useApi";
import { usePreProfile } from "~/api/usePreProfile";
import { useMount } from "~/hooks/useMount";
import { LayoutDefault } from "~/layouts";
import { ROUTES } from "~/router";
Expand All @@ -24,17 +25,16 @@ export const signUpSchema = z.object({
.string()
.min(1, { message: "Email is required" })
.email({ message: "Enter a valid email." }),
phoneNumber: z
.string().superRefine((phoneNumber, ctx) => {
const phoneWithOnlyNumbers = phoneNumber.replace(/\D/g, "");
const numberOfDigits = phoneWithOnlyNumbers.length;
if (numberOfDigits !== 10) {
ctx.addIssue({
code: "custom",
message: "Contact number must be 10 digits"
});
}
}),
phoneNumber: z.string().superRefine((phoneNumber, ctx) => {
const phoneWithOnlyNumbers = phoneNumber.replace(/\D/g, "");
const numberOfDigits = phoneWithOnlyNumbers.length;
if (numberOfDigits !== 10) {
ctx.addIssue({
code: "custom",
message: "Contact number must be 10 digits",
});
}
}),
password: z
.string()
.regex(
Expand Down Expand Up @@ -72,11 +72,10 @@ export const AccountCreation = () => {
setState,
setExperience,
} = useProfilingStore((state) => state);
// const navigate = useNavigate();
const { eligibleEmail } = useApi();

const [validatingForm, setValidatingForm] = useState(false);

const { mutate: createPreProfile } = usePreProfile().preProfileMutation;
const {
formState: { errors },
handleSubmit,
Expand All @@ -98,8 +97,16 @@ export const AccountCreation = () => {
setValidatingForm(false);
return;
} else {
setAccountData({ ...data, phoneNumber: data.phoneNumber.replace(/\D/g, "") });

setAccountData({
...data,
phoneNumber: data.phoneNumber.replace(/\D/g, ""),
});
createPreProfile({
first_name: data.firstName,
last_name: data.lastName,
email: data.email,
phone_number: data.phoneNumber.replace(/\D/g, ""),
});
switch (channel) {
case "cancer":
navigate(ROUTES.cancerForm);
Expand Down Expand Up @@ -211,10 +218,11 @@ 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 care.
I agree to receive emails and text messages related to my
care.
</Typography>
}
/>
Expand All @@ -232,7 +240,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

0 comments on commit 6affdfc

Please sign in to comment.