Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/src/types/Company.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const CreateCompanyDTOSchema = z.object({
name: z.string().min(1),
businessOwnerFullName: z.string().nonempty(),
companyType: z.enum(CompanyTypesEnum),
alternateEmail: z.email().optional(),
alternateEmail: z.preprocess((val) => (val === "" ? undefined : val), z.email().optional()),
});

export const CreateCompanyResponseSchema = CompanySchema;
Expand Down
1 change: 1 addition & 0 deletions frontend/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const createUser = async (payload: CreateUserRequest): Promise<User> => {
onboarding_step: requiredOnboardingProgress.COMPANY,
},
});
console.log(error);
return data!;
} else {
throw Error(error?.error);
Expand Down
19 changes: 6 additions & 13 deletions frontend/app/signup/company.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ import { CreateLocationBulkRequest, CreateLocationRequest } from "@/types/locati
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from "@/components/ui/select";
import { useMutation } from "@tanstack/react-query";
import React, { useState } from "react";
import { Dispatch, SetStateAction } from "react";
import { Spinner } from "@/components/ui/spinner";
import { Card } from "@/components/ui/card";
import { IoAddCircleOutline } from "react-icons/io5";

interface CompanyInfoProps {
progress: number;
setProgress: Dispatch<SetStateAction<number>>;
handleNext: () => void;
}

export default function Company({ progress, setProgress }: CompanyInfoProps) {
export default function Company({ handleNext: incrementNext }: CompanyInfoProps) {
const [companyError, setCompanyError] = useState<string | null>(null);
const [locError, setLocError] = useState<string | null>(null);

Expand Down Expand Up @@ -72,13 +70,10 @@ export default function Company({ progress, setProgress }: CompanyInfoProps) {
const { isPending: isLocationPending, mutate: mutateLocation } = useMutation({
mutationFn: (payload: CreateLocationBulkRequest) => createLocationBulk(payload),
onSuccess: () => {
setProgress(progress + 1);
incrementNext();
},
onError: (error: Error) => {
console.error("Error creating locations:", error);
if (error.message.includes("postalCode")) {
setLocError("Error creating locations. Please check postal code details and try again.");
}
onError: (_error: Error) => {
setLocError("Error creating locations. Check required fields and try again");
},
});

Expand Down Expand Up @@ -175,7 +170,6 @@ export default function Company({ progress, setProgress }: CompanyInfoProps) {
>
<SelectTrigger
id="businessType"
//className="px-[28px] py-[16px] h-[45px] rounded-[10px] placeholder:text-gray-400 placeholder:text-[16px] bg-transparent text-[16px]"
style={{
height: "45px",
width: "100%",
Expand Down Expand Up @@ -213,13 +207,12 @@ export default function Company({ progress, setProgress }: CompanyInfoProps) {
</div>
<div className="flex flex-col gap-[8px] w-full mb-[30px]">
<Label htmlFor="owner" className="text-[16px]">
Secondary Email (Optional) <span className="text-red-500 text-[16px]">*</span>
Secondary Email (Optional)
</Label>
<Input
id="owner"
name="owner"
type="text"
required
className="px-[28px] py-[16px] h-[45px] rounded-[10px] placeholder:text-gray-400 placeholder:text-[16px] bg-transparent text-[16px]"
onChange={(e) => setCompanyPayload({ ...companyPayload, alternateEmail: e.target.value })}
/>
Expand Down
11 changes: 4 additions & 7 deletions frontend/app/signup/insurance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ import { Spinner } from "@/components/ui/spinner";
import { CreateInsurancePolicyBulkRequest, CreateInsurancePolicyRequest } from "@/types/insurance-policy";
import { useMutation } from "@tanstack/react-query";
import React from "react";
import { Dispatch } from "react";
import { SetStateAction } from "react";
import { IoAddCircleOutline } from "react-icons/io5";

interface InsuranceInfoProps {
progress: number;
setProgress: Dispatch<SetStateAction<number>>;
handleNext: () => void;
}

export default function Insurance({ progress, setProgress }: InsuranceInfoProps) {
export default function Insurance({ handleNext: incrementProgress }: InsuranceInfoProps) {
const [insurancePayload, setInsurancePayload] = React.useState<CreateInsurancePolicyBulkRequest>([
{
policyName: "",
Expand All @@ -30,7 +27,7 @@ export default function Insurance({ progress, setProgress }: InsuranceInfoProps)
const { mutate: bulkCreateInsurance, isPending: createInsurancePending } = useMutation({
mutationFn: () => createInsurancePolicyBulk(insurancePayload),
onSuccess: () => {
setProgress(progress + 1);
incrementProgress();
},
onError: (error: Error) => {
setError(error.message || "An error occurred while creating insurance policies.");
Expand Down Expand Up @@ -145,7 +142,7 @@ export default function Insurance({ progress, setProgress }: InsuranceInfoProps)
<Button
type="button"
variant="link"
onClick={() => setProgress(progress + 1)}
onClick={() => incrementProgress()}
className="underline hover:text-stone-200 h-fit w-fit text-[12px] font-bold p-0"
>
Skip for now
Expand Down
23 changes: 18 additions & 5 deletions frontend/app/signup/onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,35 @@ export default function Onboarding({ email }: OnboardingProps) {
const router = useRouter();
const searchParams = useSearchParams();
const stage = parseInt(searchParams.get("stage") || "0");
const [progress, setProgress] = useState(stage);
const [progress, setProgress] = useState(getStep(stage));

const incrementProgress = () => {
setProgress((prev) => prev + 1);
};

const infoSteps = [0, 2, 4, 7];

function getStep(stage: number): number {
switch (stage) {
case 0:
return 2;
case 1:
return 3;
case 2:
return 7;
default:
return 0;
}
}

const components = [
<InfoPage
key={0}
handleNext={incrementProgress}
title={"First we'll need some basic\ninformation to set up your account."}
description="This information will help set up your profile."
/>,
<UserInfoPage key={1} email={email} progress={progress} setProgress={setProgress} />,
<UserInfoPage key={1} email={email} handleNext={incrementProgress} />,
<InfoPage
key={2}
handleNext={incrementProgress}
Expand All @@ -51,16 +64,16 @@ export default function Onboarding({ email }: OnboardingProps) {
/>
}
/>,
<Company key={3} progress={progress} setProgress={setProgress} />,
<Company key={3} handleNext={incrementProgress} />,
<InfoPage
key={4}
handleNext={incrementProgress}
title={"Enter insurance information."}
description="This is an optional step but will be helpful if you choose to file a claim report."
optional={true}
/>,
<Insurance key={5} progress={progress} setProgress={setProgress} />,
<Quickbooks key={6} progress={progress} setProgress={setProgress} />,
<Insurance key={5} handleNext={incrementProgress} />,
<Quickbooks key={6} handleNext={incrementProgress} />,
<InfoPage
key={7}
handleNext={() => router.push("/")}
Expand Down
Empty file.
8 changes: 3 additions & 5 deletions frontend/app/signup/quickbooks.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { Dispatch, SetStateAction } from "react";
import { GoSync } from "react-icons/go";
import { FiUpload } from "react-icons/fi";

interface QuickbooksInfoProps {
progress: number;
setProgress: Dispatch<SetStateAction<number>>;
handleNext: () => void;
}

export default function Quickbooks({ progress, setProgress }: QuickbooksInfoProps) {
export default function Quickbooks({ handleNext }: QuickbooksInfoProps) {
return (
<Card className="w-full px-[163px] py-[127px]">
<div className="flex justify-center">
Expand Down Expand Up @@ -46,7 +44,7 @@ export default function Quickbooks({ progress, setProgress }: QuickbooksInfoProp
<Button
type="button"
variant="link"
onClick={() => setProgress(progress + 1)}
onClick={() => handleNext()}
className="underline hover:text-stone-200 h-fit w-fit text-[12px] font-bold p-0"
>
Skip for now
Expand Down
57 changes: 0 additions & 57 deletions frontend/app/signup/user-info.tsx

This file was deleted.

8 changes: 3 additions & 5 deletions frontend/app/signup/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import { Spinner } from "@/components/ui/spinner";
import { CreateUserRequest } from "@/types/user";
import { useMutation } from "@tanstack/react-query";
import { useState } from "react";
import { Dispatch, SetStateAction } from "react";

interface UserInfoProps {
email: string;
progress: number;
setProgress: Dispatch<SetStateAction<number>>;
handleNext: () => void;
}
export default function UserInfoPage({ email, progress, setProgress }: UserInfoProps) {
export default function UserInfoPage({ email, handleNext }: UserInfoProps) {
const [payload, setPayload] = useState<CreateUserRequest>({
firstName: "",
lastName: "",
Expand All @@ -25,7 +23,7 @@ export default function UserInfoPage({ email, progress, setProgress }: UserInfoP
const { isPending, mutate } = useMutation({
mutationFn: (payload: CreateUserRequest) => createUser(payload),
onSuccess: () => {
setProgress(progress + 1);
handleNext();
},
onError: (error: Error) => {
setFieldError(error.message || "An error occurred while creating the user.");
Expand Down
1 change: 1 addition & 0 deletions frontend/types/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type signupInitialState = {
export enum requiredOnboardingProgress {
USER = "user",
COMPANY = "company",

FINISHED = "finished",
}

Expand Down
1 change: 1 addition & 0 deletions frontend/utils/supabase/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function createSupabaseClient() {
*/
export async function getAuthToken(): Promise<string> {
const supabase = createSupabaseClient();
("@ts-expect-error");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We don't care about this error bc we validate the access token in the backend

const { data, error } = await supabase.auth.getSession();

if (error) {
Expand Down
24 changes: 16 additions & 8 deletions frontend/utils/supabase/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ export async function updateSession(request: NextRequest) {

const isOnSignupPage = request.nextUrl.pathname === "/signup" && request.nextUrl.searchParams.has("stage");
if (
!isOnSignupPage &&
user &&
user.user_metadata.onboarding_step &&
user.user_metadata.onboarding_step != requiredOnboardingProgress.FINISHED
(!isOnSignupPage &&
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

can def simplify this boolean logic ... maybe tmr

user &&
user.user_metadata.onboarding_step &&
user.user_metadata.onboarding_step != requiredOnboardingProgress.FINISHED) ||
(isOnSignupPage &&
user &&
user.user_metadata.onboarding_step &&
progressToNumber[user.user_metadata.onboarding_step as requiredOnboardingProgress] !=
parseInt(request.nextUrl.searchParams.get("stage")!))
) {
const url = request.nextUrl.clone();
url.pathname = `/signup`;
Expand All @@ -57,16 +62,19 @@ export async function updateSession(request: NextRequest) {
) {
const url = request.nextUrl.clone();
url.pathname = `/`;
url.search = "";
return NextResponse.redirect(url);
}
if (
!user &&
!request.nextUrl.pathname.startsWith("/login") &&
!request.nextUrl.pathname.startsWith("/signup") &&
!request.nextUrl.pathname.startsWith("/error")
(!user &&
!request.nextUrl.pathname.startsWith("/login") &&
!request.nextUrl.pathname.startsWith("/signup") &&
!request.nextUrl.pathname.startsWith("/error")) ||
(!user && isOnSignupPage)
) {
const url = request.nextUrl.clone();
url.pathname = "/login";
url.search = "";
return NextResponse.redirect(url);
}
return supabaseResponse;
Expand Down
Loading