2023-11-20 14:01:19 +00:00
|
|
|
import React from "react";
|
2023-11-23 08:15:00 +00:00
|
|
|
import { Controller, useForm } from "react-hook-form";
|
2023-07-12 14:25:08 +00:00
|
|
|
// hooks
|
|
|
|
import useUser from "hooks/use-user";
|
2023-11-20 14:01:19 +00:00
|
|
|
// components
|
2023-11-25 16:01:09 +00:00
|
|
|
import { Invitations, OnboardingSidebar, OnboardingStepIndicator, Workspace } from "components/onboarding";
|
2023-07-12 14:25:08 +00:00
|
|
|
// types
|
2023-11-20 14:01:19 +00:00
|
|
|
import { IWorkspace, TOnboardingSteps } from "types";
|
2023-07-12 14:25:08 +00:00
|
|
|
|
|
|
|
type Props = {
|
2023-07-31 11:53:49 +00:00
|
|
|
finishOnboarding: () => Promise<void>;
|
|
|
|
stepChange: (steps: Partial<TOnboardingSteps>) => Promise<void>;
|
2023-11-20 14:01:19 +00:00
|
|
|
setTryDiffAccount: () => void;
|
2023-07-12 14:25:08 +00:00
|
|
|
};
|
|
|
|
|
2023-11-20 14:01:19 +00:00
|
|
|
export const JoinWorkspaces: React.FC<Props> = ({ stepChange, setTryDiffAccount }) => {
|
2023-07-12 14:25:08 +00:00
|
|
|
const { user } = useUser();
|
2023-11-20 14:01:19 +00:00
|
|
|
const {
|
|
|
|
handleSubmit,
|
|
|
|
control,
|
|
|
|
setValue,
|
|
|
|
watch,
|
2023-11-29 15:02:10 +00:00
|
|
|
formState: { errors, isSubmitting },
|
2023-11-20 14:01:19 +00:00
|
|
|
} = useForm<IWorkspace>({
|
|
|
|
defaultValues: {
|
|
|
|
name: "",
|
2023-12-01 09:48:48 +00:00
|
|
|
slug: "",
|
2023-11-20 14:01:19 +00:00
|
|
|
},
|
|
|
|
mode: "onChange",
|
|
|
|
});
|
2023-07-12 14:25:08 +00:00
|
|
|
|
2023-07-31 11:53:49 +00:00
|
|
|
const handleNextStep = async () => {
|
2023-07-12 14:25:08 +00:00
|
|
|
if (!user) return;
|
2023-11-20 14:01:19 +00:00
|
|
|
await stepChange({ workspace_join: true, workspace_create: true });
|
2023-07-12 14:25:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2023-11-23 08:15:00 +00:00
|
|
|
<div className="flex w-full">
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="fixed hidden h-full w-1/5 max-w-[320px] lg:block">
|
2023-11-20 14:01:19 +00:00
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="name"
|
|
|
|
render={({ field: { value } }) => (
|
2023-11-25 16:01:09 +00:00
|
|
|
<OnboardingSidebar
|
2023-11-20 14:01:19 +00:00
|
|
|
watch={watch}
|
|
|
|
setValue={setValue}
|
|
|
|
control={control}
|
|
|
|
showProject={false}
|
|
|
|
workspaceName={value.length > 0 ? value : "New Workspace"}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
2023-07-12 14:25:08 +00:00
|
|
|
</div>
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="ml-auto w-full lg:w-2/3 ">
|
|
|
|
<div className="mx-auto my-16 w-full px-7 lg:w-4/5 lg:px-0">
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
<p className="text-xl font-semibold text-onboarding-text-200 sm:text-2xl">What will your workspace be?</p>
|
2023-11-23 08:15:00 +00:00
|
|
|
<OnboardingStepIndicator step={1} />
|
|
|
|
</div>
|
|
|
|
<Workspace
|
|
|
|
stepChange={stepChange}
|
|
|
|
user={user}
|
|
|
|
control={control}
|
|
|
|
handleSubmit={handleSubmit}
|
|
|
|
setValue={setValue}
|
|
|
|
errors={errors}
|
|
|
|
isSubmitting={isSubmitting}
|
|
|
|
/>
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="my-8 flex items-center md:w-1/2">
|
|
|
|
<hr className="w-full border-onboarding-border-100" />
|
|
|
|
<p className="mx-3 flex-shrink-0 text-center text-sm text-custom-text-400">Or</p>
|
|
|
|
<hr className="w-full border-onboarding-border-100" />
|
2023-11-23 08:15:00 +00:00
|
|
|
</div>
|
|
|
|
<div className="w-full">
|
|
|
|
<Invitations setTryDiffAccount={setTryDiffAccount} handleNextStep={handleNextStep} />
|
|
|
|
</div>
|
2023-11-20 14:01:19 +00:00
|
|
|
</div>
|
2023-07-12 14:25:08 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|