chore: onboarding (#2790)

* style: onboarding light version

* style: dark mode

* fix: onboarding gradient

* refactor: imports

* chore: add use case field in users api

* feat: delete account

* fix: delete modal points alignment

* feat: usecase in profile

* fix: build error

* fix: typos & hardcoded strings

---------

Co-authored-by: pablohashescobar <nikhilschacko@gmail.com>
This commit is contained in:
Lakhan Baheti 2023-11-20 19:31:19 +05:30 committed by sriram veeraghanta
parent 9d5f835bea
commit 6512b8205f
25 changed files with 2674 additions and 580 deletions

View file

@ -0,0 +1,172 @@
// react
import React, { useState } from "react";
// components
import { Button, Loader } from "@plane/ui";
// helpers
import { truncateText } from "helpers/string.helper";
// mobx
import { useMobxStore } from "lib/mobx/store-provider";
// services
import { WorkspaceService } from "services/workspace.service";
// swr
import useSWR, { mutate } from "swr";
// contants
import { USER_WORKSPACES, USER_WORKSPACE_INVITATIONS } from "constants/fetch-keys";
import { ROLE } from "constants/workspace";
// types
import { IWorkspaceMemberInvitation } from "types";
// icons
import { CheckCircle2, Search } from "lucide-react";
import { trackEvent } from "helpers/event-tracker.helper";
type Props = {
handleNextStep: () => void;
setTryDiffAccount: () => void;
};
const workspaceService = new WorkspaceService();
const Invitations: React.FC<Props> = (props) => {
const { handleNextStep, setTryDiffAccount } = props;
const [isJoiningWorkspaces, setIsJoiningWorkspaces] = useState(false);
const [invitationsRespond, setInvitationsRespond] = useState<string[]>([]);
const {
workspace: workspaceStore,
user: { currentUser, updateCurrentUser },
} = useMobxStore();
const {
data: invitations,
mutate: mutateInvitations,
isLoading,
} = useSWR(USER_WORKSPACE_INVITATIONS, () => workspaceService.userWorkspaceInvitations());
const handleInvitation = (workspace_invitation: IWorkspaceMemberInvitation, action: "accepted" | "withdraw") => {
if (action === "accepted") {
setInvitationsRespond((prevData) => [...prevData, workspace_invitation.id]);
} else if (action === "withdraw") {
setInvitationsRespond((prevData) => prevData.filter((item: string) => item !== workspace_invitation.id));
}
};
const updateLastWorkspace = async () => {
if (!workspaceStore.workspaces) return;
await updateCurrentUser({
last_workspace_id: workspaceStore.workspaces[0].id,
});
};
const submitInvitations = async () => {
if (invitationsRespond.length <= 0) return;
setIsJoiningWorkspaces(true);
await workspaceService
.joinWorkspaces({ invitations: invitationsRespond })
.then(async (res) => {
trackEvent("WORKSPACE_USER_INVITE_ACCEPT", res);
await mutateInvitations();
await workspaceStore.fetchWorkspaces();
await mutate(USER_WORKSPACES);
await updateLastWorkspace();
await handleNextStep();
})
.finally(() => setIsJoiningWorkspaces(false));
};
return invitations && invitations.length > 0 ? (
<div>
<div className="space-y-4 md:w-2/3 ">
<p className="font-semibold pb-2 text-xl sm:text-2xl">Choose a workspace to join </p>
<div>
{invitations &&
invitations.length > 0 &&
invitations.map((invitation) => {
const isSelected = invitationsRespond.includes(invitation.id);
return (
<div
key={invitation.id}
className={`flex cursor-pointer items-center gap-2 border p-3.5 rounded ${
isSelected
? "border-custom-primary-100"
: "border-onboarding-border-200 hover:bg-onboarding-background-300/30"
}`}
onClick={() => handleInvitation(invitation, isSelected ? "withdraw" : "accepted")}
>
<div className="flex-shrink-0">
<div className="grid place-items-center h-9 w-9 rounded">
{invitation.workspace.logo && invitation.workspace.logo !== "" ? (
<img
src={invitation.workspace.logo}
height="100%"
width="100%"
className="rounded"
alt={invitation.workspace.name}
/>
) : (
<span className="grid place-items-center h-9 w-9 py-1.5 px-3 rounded bg-gray-700 uppercase text-white">
{invitation.workspace.name[0]}
</span>
)}
</div>
</div>
<div className="min-w-0 flex-1">
<div className="text-sm font-medium">{truncateText(invitation.workspace.name, 30)}</div>
<p className="text-xs text-custom-text-200">{ROLE[invitation.role]}</p>
</div>
<span className={`flex-shrink-0 ${isSelected ? "text-custom-primary-100" : "text-custom-text-200"}`}>
<CheckCircle2 className="h-5 w-5" />
</span>
</div>
);
})}
</div>
<Button variant="primary" onClick={submitInvitations}>
{isJoiningWorkspaces ? "Joining..." : "Join your team"}
</Button>
</div>
<div className="py-3 px-4 mt-8 bg-onboarding-background-300/30 rounded-sm flex justify-between items-center">
<div className="flex items-center">
<Search className="h-4 w-4 mr-2" />
<span className="text-sm text-custom-text-200">Don&apos;t see your workspace?</span>
</div>
<div>
<div
className="bg-onboarding-background-200 py-3 text-center hover:cursor-pointer text-custom-text-200 rounded-md text-sm font-medium border border-custom-border-200"
onClick={setTryDiffAccount}
>
Try a different email address
</div>
<p className="text-xs mt-2 text-custom-text-300">
Your right e-mail address could be from a Google or GitHub login.
</p>
</div>
</div>
</div>
) : (
<EmptyInvitation email={currentUser!.email} />
);
};
const EmptyInvitation = ({ email }: { email: string }) => (
<div className="items-center md:w-4/5 bg-onboarding-background-300/30 my-16 border-onboarding-border-200 py-5 px-10 rounded border justify-center ">
<p className="text-lg text-onboarding-text-300 text-center font-semibold">Is your team already on Plane?</p>
<p className="text-sm text-onboarding-text-300 mt-6 text-center">
We couldnt find any existing workspaces for the email address {email}
</p>
<div
className="bg-onboarding-background-200 mt-6 py-3 text-center hover:cursor-pointer text-custom-text-200 rounded-md text-sm font-medium border border-custom-border-200"
onClick={() => {}}
>
Try a different email address
</div>
<p className="text-xs mt-2 text-center text-custom-text-300">
Your right e-mail address could be from a Google or GitHub login.
</p>
</div>
);
export default Invitations;

View file

@ -1,5 +1,6 @@
import React, { useEffect, useRef, useState } from "react";
// next
import Image from "next/image";
// headless ui
import { Listbox, Transition } from "@headlessui/react";
// react-hook-form
@ -10,14 +11,19 @@ import { WorkspaceService } from "services/workspace.service";
import useToast from "hooks/use-toast";
// ui
import { Button, Input } from "@plane/ui";
// components
import OnboardingStepIndicator from "components/account/step-indicator";
// hooks
import useDynamicDropdownPosition from "hooks/use-dynamic-dropdown";
// icons
import { Check, ChevronDown, Plus, X } from "lucide-react";
import { Check, ChevronDown, Plus, User2, X, XCircle } from "lucide-react";
// types
import { IUser, IWorkspace, TOnboardingSteps, TUserWorkspaceRole } from "types";
// constants
import { ROLE } from "constants/workspace";
// assets
import user1 from "public/users/user-1.png";
import user2 from "public/users/user-2.png";
type Props = {
finishOnboarding: () => Promise<void>;
@ -59,7 +65,7 @@ const InviteMemberForm: React.FC<InviteMemberFormProps> = (props) => {
return (
<div className="group relative grid grid-cols-11 gap-4">
<div className="col-span-7">
<div className="col-span-7 bg-onboarding-background-200 rounded-md">
<Controller
control={control}
name={`emails.${index}.email`}
@ -80,12 +86,12 @@ const InviteMemberForm: React.FC<InviteMemberFormProps> = (props) => {
ref={ref}
hasError={Boolean(errors.emails?.[index]?.email)}
placeholder="Enter their email..."
className="text-xs sm:text-sm w-full"
className="text-xs sm:text-sm w-full h-12 placeholder:text-onboarding-text-400 border-onboarding-border-100"
/>
)}
/>
</div>
<div className="col-span-3">
<div className="col-span-3 bg-onboarding-background-200 rounded-md border items-center flex border-onboarding-border-100">
<Controller
control={control}
name={`emails.${index}.role`}
@ -104,10 +110,11 @@ const InviteMemberForm: React.FC<InviteMemberFormProps> = (props) => {
type="button"
ref={buttonRef}
onClick={() => setIsDropdownOpen((prev) => !prev)}
className="flex items-center px-2.5 py-2 text-xs justify-between gap-1 w-full rounded-md border border-custom-border-300 shadow-sm duration-300 focus:outline-none"
className="flex items-center px-2.5 h-11 py-2 text-xs justify-between gap-1 w-full rounded-md duration-300"
>
<span className="text-xs sm:text-sm">{ROLE[value]}</span>
<ChevronDown className="h-3 w-3" aria-hidden="true" />
<span className="text-xs text-onboarding-text-400 sm:text-sm">{ROLE[value]}</span>
<ChevronDown className="h-4 w-4 stroke-onboarding-text-400" />
</Listbox.Button>
<Transition
@ -122,7 +129,7 @@ const InviteMemberForm: React.FC<InviteMemberFormProps> = (props) => {
>
<Listbox.Options
ref={dropdownRef}
className="fixed w-36 z-10 border border-custom-border-300 mt-1 overflow-y-auto rounded-md bg-custom-background-90 text-xs shadow-lg focus:outline-none max-h-48"
className="fixed w-36 z-10 border border-onboarding-border-100 mt-1 overflow-y-auto rounded-md bg-onboarding-background-200 text-xs shadow-lg focus:outline-none max-h-48"
>
<div className="space-y-1 p-2">
{Object.entries(ROLE).map(([key, value]) => (
@ -131,8 +138,8 @@ const InviteMemberForm: React.FC<InviteMemberFormProps> = (props) => {
value={parseInt(key)}
className={({ active, selected }) =>
`cursor-pointer select-none truncate rounded px-1 py-1.5 ${
active || selected ? "bg-custom-background-80" : ""
} ${selected ? "text-custom-text-100" : "text-custom-text-200"}`
active || selected ? "bg-onboarding-background-400/40" : ""
} ${selected ? "text-onboarding-text-100" : "text-custom-text-200"}`
}
>
{({ selected }) => (
@ -153,10 +160,10 @@ const InviteMemberForm: React.FC<InviteMemberFormProps> = (props) => {
{fields.length > 1 && (
<button
type="button"
className="hidden group-hover:grid self-center place-items-center rounded -ml-3"
className="hidden group-hover:grid self-center place-items-center rounded ml-3"
onClick={() => remove(index)}
>
<X className="h-3.5 w-3.5 text-custom-text-200" />
<XCircle className="h-3.5 w-3.5 text-custom-text-400" />
</button>
)}
</div>
@ -182,7 +189,6 @@ export const InviteMembers: React.FC<Props> = (props) => {
const nextStep = async () => {
const payload: Partial<TOnboardingSteps> = {
workspace_invite: true,
workspace_join: true,
};
await stepChange(payload);
@ -223,49 +229,94 @@ export const InviteMembers: React.FC<Props> = (props) => {
}, [fields, append]);
return (
<form
className="w-full space-y-7 sm:space-y-10 overflow-hidden flex flex-col"
onSubmit={handleSubmit(onSubmit)}
onKeyDown={(e) => {
if (e.code === "Enter") e.preventDefault();
}}
>
<h2 className="text-xl sm:text-2xl font-semibold">Invite people to collaborate</h2>
<div className="md:w-3/5 text-sm h-full max-h-[40vh] flex flex-col overflow-hidden">
<div className="grid grid-cols-11 gap-x-4 mb-1 text-sm">
<h6 className="col-span-7">Co-workers Email</h6>
<h6 className="col-span-4">Role</h6>
<div className="flex py-14">
<div
className={`hidden lg:block w-1/4 p-3 ml-auto rounded bg-onboarding-gradient-secondary border border-onboarding-border-100 border-opacity-10`}
>
<p className="text-base text-onboarding-text-400 font-semibold">Members</p>
{Array.from({ length: 4 }).map(() => (
<div className="flex items-center gap-2 mt-4">
<div className="w-8 h-8 flex justify-center items-center flex-shrink-0 rounded-full bg-onboarding-background-400">
<User2 className="h-4 w-4 stroke-onboarding-background-300 fill-onboarding-background-400" />
</div>
<div className="w-full">
<div className="rounded-md h-2.5 my-2 bg-onboarding-background-100 w-2/3" />
<div className="rounded-md h-2 bg-onboarding-background-400 w-1/2" />
</div>
</div>
))}
<div className="relative mt-20 h-32">
<div className="flex absolute bg-onboarding-background-200 p-2 rounded-full gap-x-2 border border-onboarding-border-100 w-full mt-1 -left-1/2">
<div className="w-8 h-8 flex-shrink-0 rounded-full bg-custom-primary-10">
<Image src={user2} alt="user" />
</div>
<div>
<p className="text-sm font-medium">Murphy cooper</p>
<p className="text-onboarding-text-400 text-sm">murphy@plane.so</p>
</div>
</div>
<div className="flex absolute bg-onboarding-background-200 p-2 rounded-full gap-x-2 border border-onboarding-border-100 -left-1/3 mt-14 w-full">
<div className="w-8 h-8 flex-shrink-0 rounded-full bg-custom-primary-10">
<Image src={user1} alt="user" />
</div>
<div>
<p className="text-sm font-medium">Else Thompson</p>
<p className="text-onboarding-text-400 text-sm">Elsa@plane.so</p>
</div>
</div>
</div>
<div className="space-y-3 sm:space-y-4 mb-3 h-full overflow-y-auto">
{fields.map((field, index) => (
<InviteMemberForm
control={control}
errors={errors}
field={field}
fields={fields}
index={index}
remove={remove}
key={field.id}
/>
))}
</div>
<form
className="px-7 sm:px-0 md:w-4/5 lg:w-1/2 mx-auto space-y-7 sm:space-y-10 overflow-hidden flex flex-col"
onSubmit={handleSubmit(onSubmit)}
onKeyDown={(e) => {
if (e.code === "Enter") e.preventDefault();
}}
>
<div className="flex justify-between items-center">
<h2 className="text-xl sm:text-2xl font-semibold">Invite your team to work with you</h2>
<OnboardingStepIndicator step={2} />
</div>
<button
type="button"
className="flex items-center gap-2 outline-custom-primary-100 bg-transparent text-custom-primary-100 text-xs font-medium py-2 pr-3"
onClick={appendField}
>
<Plus className="h-3 w-3" />
Add another
</button>
</div>
<div className="flex items-center gap-4">
<Button variant="primary" type="submit" disabled={!isValid} loading={isSubmitting} size="md">
{isSubmitting ? "Sending..." : "Send Invite"}
</Button>
<Button variant="neutral-primary" size="md" onClick={nextStep}>
Skip this step
</Button>
</div>
</form>
<div className="md:w-4/5 text-sm flex flex-col overflow-hidden">
<div className="space-y-3 sm:space-y-4 mb-3 h-full overflow-y-auto">
{fields.map((field, index) => (
<InviteMemberForm
control={control}
errors={errors}
field={field}
fields={fields}
index={index}
remove={remove}
key={field.id}
/>
))}
</div>
<button
type="button"
className="flex items-center gap-2 outline-custom-primary-100 bg-transparent text-custom-primary-100 text-sm font-semibold py-2 pr-3"
onClick={appendField}
>
<Plus className="h-3 w-3" />
Add another
</button>
</div>
<div className="flex items-center gap-4">
<Button variant="primary" type="submit" disabled={!isValid} loading={isSubmitting} size="md">
{isSubmitting ? "Sending..." : "Send Invite"}
</Button>
{/* <Button variant="outline-primary" size="md" onClick={nextStep}>
Copy invite link
</Button> */}
<span className="text-sm text-onboarding-text-400 hover:cursor-pointer" onClick={nextStep}>
Do this later
</span>
</div>
</form>
</div>
);
};

View file

@ -1,139 +1,83 @@
import React, { useState } from "react";
import useSWR, { mutate } from "swr";
// services
import { WorkspaceService } from "services/workspace.service";
import React from "react";
// hooks
import useUser from "hooks/use-user";
// ui
import { Button } from "@plane/ui";
// icons
import { CheckCircle } from "lucide-react";
// helpers
import { truncateText } from "helpers/string.helper";
// components
import Invitations from "./invitations";
import DummySidebar from "components/account/sidebar";
import OnboardingStepIndicator from "components/account/step-indicator";
import { Workspace } from "./workspace";
// types
import { IWorkspaceMemberInvitation, TOnboardingSteps } from "types";
// fetch-keys
import { USER_WORKSPACES, USER_WORKSPACE_INVITATIONS } from "constants/fetch-keys";
// constants
import { ROLE } from "constants/workspace";
import { trackEvent } from "helpers/event-tracker.helper";
import { IWorkspace, TOnboardingSteps } from "types";
// react-hook-form
import { Controller, useForm } from "react-hook-form";
type Props = {
finishOnboarding: () => Promise<void>;
stepChange: (steps: Partial<TOnboardingSteps>) => Promise<void>;
updateLastWorkspace: () => Promise<void>;
setTryDiffAccount: () => void;
};
// services
const workspaceService = new WorkspaceService();
export const JoinWorkspaces: React.FC<Props> = ({ finishOnboarding, stepChange, updateLastWorkspace }) => {
const [isJoiningWorkspaces, setIsJoiningWorkspaces] = useState(false);
const [invitationsRespond, setInvitationsRespond] = useState<string[]>([]);
export const JoinWorkspaces: React.FC<Props> = ({ stepChange, setTryDiffAccount }) => {
const { user } = useUser();
const { data: invitations, mutate: mutateInvitations } = useSWR(USER_WORKSPACE_INVITATIONS, () =>
workspaceService.userWorkspaceInvitations()
);
const handleInvitation = (workspace_invitation: IWorkspaceMemberInvitation, action: "accepted" | "withdraw") => {
if (action === "accepted") {
setInvitationsRespond((prevData) => [...prevData, workspace_invitation.id]);
} else if (action === "withdraw") {
setInvitationsRespond((prevData) => prevData.filter((item: string) => item !== workspace_invitation.id));
}
};
const {
handleSubmit,
control,
setValue,
watch,
formState: { errors, isSubmitting, isValid },
} = useForm<IWorkspace>({
defaultValues: {
name: "",
slug: `${window.location.host}/`,
},
mode: "onChange",
});
const handleNextStep = async () => {
if (!user) return;
await stepChange({ workspace_join: true });
if (user.onboarding_step.workspace_create && user.onboarding_step.workspace_invite) await finishOnboarding();
};
const submitInvitations = async () => {
if (invitationsRespond.length <= 0) return;
setIsJoiningWorkspaces(true);
await workspaceService
.joinWorkspaces({ invitations: invitationsRespond })
.then(async (res) => {
trackEvent(
'WORKSPACE_USER_INVITE_ACCEPT',
res
)
await mutateInvitations();
await mutate(USER_WORKSPACES);
await updateLastWorkspace();
await handleNextStep();
})
.finally(() => setIsJoiningWorkspaces(false));
await stepChange({ workspace_join: true, workspace_create: true });
};
return (
<div className="w-full space-y-7 sm:space-y-10">
<h5 className="sm:text-lg">We see that someone has invited you to</h5>
<h4 className="text-xl sm:text-2xl font-semibold">Join a workspace</h4>
<div className="max-h-[37vh] overflow-y-auto md:w-3/5 space-y-4">
{invitations &&
invitations.map((invitation) => {
const isSelected = invitationsRespond.includes(invitation.id);
return (
<div
key={invitation.id}
className={`flex cursor-pointer items-center gap-2 border py-5 px-3.5 rounded ${isSelected ? "border-custom-primary-100" : "border-custom-border-200 hover:bg-custom-background-80"
}`}
onClick={() => handleInvitation(invitation, isSelected ? "withdraw" : "accepted")}
>
<div className="flex-shrink-0">
<div className="grid place-items-center h-9 w-9 rounded">
{invitation.workspace.logo && invitation.workspace.logo !== "" ? (
<img
src={invitation.workspace.logo}
height="100%"
width="100%"
className="rounded"
alt={invitation.workspace.name}
/>
) : (
<span className="grid place-items-center h-9 w-9 py-1.5 px-3 rounded bg-gray-700 uppercase text-white">
{invitation.workspace.name[0]}
</span>
)}
</div>
</div>
<div className="min-w-0 flex-1">
<div className="text-sm font-medium">{truncateText(invitation.workspace.name, 30)}</div>
<p className="text-xs text-custom-text-200">{ROLE[invitation.role]}</p>
</div>
<span className={`flex-shrink-0 ${isSelected ? "text-custom-primary-100" : "text-custom-text-200"}`}>
<CheckCircle className="h-5 w-5" />
</span>
</div>
);
})}
<div className="flex h-full w-full">
<div className="hidden lg:block w-3/12">
<Controller
control={control}
name="name"
render={({ field: { value } }) => (
<DummySidebar
watch={watch}
setValue={setValue}
control={control}
showProject={false}
workspaceName={value.length > 0 ? value : "New Workspace"}
/>
)}
/>
</div>
<div className="flex items-center gap-3">
<Button
variant="primary"
type="submit"
size="md"
onClick={submitInvitations}
disabled={invitationsRespond.length === 0}
loading={isJoiningWorkspaces}
>
Accept & Join
</Button>
<Button variant="neutral-primary" size="md" onClick={handleNextStep}>
Skip for now
</Button>
<div className="w-full lg:w-1/2 md:w-4/5 md:px-0 px-7 my-16 mx-auto">
<div className="flex justify-between items-center">
<p className="font-semibold text-onboarding-text-200 text-xl sm:text-2xl">What will your workspace be?</p>
<OnboardingStepIndicator step={1} />
</div>
<Workspace
stepChange={stepChange}
user={user}
control={control}
handleSubmit={handleSubmit}
setValue={setValue}
errors={errors}
isSubmitting={isSubmitting}
/>
<div className="flex md:w-4/5 items-center my-8">
<hr className="border-onboarding-border-100 w-full" />
<p className="text-center text-sm text-custom-text-400 mx-3 flex-shrink-0">Or</p>
<hr className="border-onboarding-border-100 w-full" />
</div>
<div className="w-full">
<Invitations setTryDiffAccount={setTryDiffAccount} handleNextStep={handleNextStep} />
</div>
</div>
</div>
);

View file

@ -1,22 +1,29 @@
import { useEffect } from "react";
// react
import React, { useState } from "react";
// next
import Image from "next/image";
import { Controller, useForm } from "react-hook-form";
import { observer } from "mobx-react-lite";
// mobx store
import { useMobxStore } from "lib/mobx/store-provider";
// ui
import { Button, CustomSelect, CustomSearchSelect, Input } from "@plane/ui";
// components
import { Button, Input } from "@plane/ui";
import DummySidebar from "components/account/sidebar";
import OnboardingStepIndicator from "components/account/step-indicator";
// types
import { IUser } from "types";
// helpers
import { getUserTimeZoneFromWindow } from "helpers/date-time.helper";
// constants
import { USER_ROLES } from "constants/workspace";
import { TIME_ZONES } from "constants/timezones";
// assets
import IssuesSvg from "public/onboarding/onboarding-issues.svg";
import { ImageUploadModal } from "components/core";
// icons
import { Camera, User2 } from "lucide-react";
const defaultValues: Partial<IUser> = {
first_name: "",
last_name: "",
role: "",
avatar: "",
use_case: undefined,
};
type Props = {
@ -31,13 +38,16 @@ const timeZoneOptions = TIME_ZONES.map((timeZone) => ({
export const UserDetails: React.FC<Props> = observer((props) => {
const { user } = props;
const [isRemoving, setIsRemoving] = useState(false);
const [selectedUsecase, setSelectedUsecase] = useState<number | null>();
const [isImageUploadModalOpen, setIsImageUploadModalOpen] = useState(false);
const { user: userStore } = useMobxStore();
const {
handleSubmit,
control,
reset,
watch,
setValue,
formState: { errors, isSubmitting, isValid },
} = useForm<IUser>({
defaultValues,
@ -48,6 +58,9 @@ export const UserDetails: React.FC<Props> = observer((props) => {
const payload: Partial<IUser> = {
...formData,
first_name: formData.first_name.split(" ")[0],
last_name: formData.first_name.split(" ")[1],
use_case: formData.use_case,
onboarding_step: {
...user.onboarding_step,
profile_complete: true,
@ -57,136 +70,130 @@ export const UserDetails: React.FC<Props> = observer((props) => {
await userStore.updateCurrentUser(payload);
};
useEffect(() => {
if (user) {
reset({
first_name: user.first_name,
last_name: user.last_name,
role: user.role,
user_timezone: getUserTimeZoneFromWindow(),
});
}
}, [user, reset]);
const useCases = [
"Build Products",
"Manage Feedbacks",
"Service delivery",
"Field force management",
"Code Repository Integration",
"Bug Tracking",
"Test Case Management",
"Rescource allocation",
];
return (
<form
className="h-full w-full space-y-7 sm:space-y-10 overflow-y-auto sm:flex sm:flex-col sm:items-start sm:justify-center"
onSubmit={handleSubmit(onSubmit)}
>
<div className="relative sm:text-lg">
<div className="text-custom-primary-100 absolute -top-1 -left-3">{'"'}</div>
<h5>Hey there 👋🏻</h5>
<h5 className="mt-5 mb-6">Let{"'"}s get you onboard!</h5>
<h4 className="text-xl sm:text-2xl font-semibold">Set up your Plane profile.</h4>
<div className="h-full w-full space-y-7 sm:space-y-10 overflow-y-auto flex ">
<div className="hidden lg:block w-3/12">
<DummySidebar showProject workspaceName="New Workspace" />
</div>
<ImageUploadModal
isOpen={isImageUploadModalOpen}
onClose={() => setIsImageUploadModalOpen(false)}
isRemoving={isRemoving}
handleDelete={() => {}}
onSuccess={(url) => {
setValue("avatar", url);
setIsImageUploadModalOpen(false);
}}
value={watch("avatar") !== "" ? watch("avatar") : undefined}
userImage
/>
<div className="flex lg:w-3/5 md:w-4/5 md:px-0 px-7 mx-auto flex-col">
<form onSubmit={handleSubmit(onSubmit)} className="md:w-11/12 mx-auto">
<div className="flex justify-between items-center">
<p className="font-semibold text-xl sm:text-2xl">What do we call you? </p>
<OnboardingStepIndicator step={2} />
</div>
<div className="flex mt-5 w-full ">
<button type="button" onClick={() => setIsImageUploadModalOpen(true)}>
{!watch("avatar") || watch("avatar") === "" ? (
<div className="h-16 hover:cursor-pointer justify-center items-center flex w-16 rounded-full flex-shrink-0 mr-3 relative bg-onboarding-background-300">
<div className="h-6 w-6 flex justify-center items-center bottom-1 border border-onboarding-border-100 -right-1 bg-onboarding-background-100 rounded-full absolute">
<Camera className="h-4 w-4 stroke-onboarding-background-400" />
</div>
<User2 className="h-10 w-10 stroke-onboarding-background-300 fill-onboarding-background-400" />
</div>
) : (
<div className="relative h-16 w-16 overflow-hidden mr-3">
<img
src={watch("avatar")}
className="absolute top-0 left-0 h-full w-full object-cover rounded-full"
onClick={() => setIsImageUploadModalOpen(true)}
alt={user?.display_name}
/>
</div>
)}
</button>
<div className="space-y-7 sm:w-3/4 md:w-2/5">
<div className="space-y-1 text-sm">
<label htmlFor="firstName">First Name</label>
<Controller
control={control}
name="first_name"
rules={{
required: "First name is required",
maxLength: {
value: 24,
message: "First name cannot exceed the limit of 24 characters",
},
}}
render={({ field: { value, onChange, ref } }) => (
<Input
id="first_name"
<div className="my-2 bg-onboarding-background-200 w-full mr-10 rounded-md flex text-sm">
<Controller
control={control}
name="first_name"
type="text"
value={value}
onChange={onChange}
ref={ref}
hasError={Boolean(errors.first_name)}
placeholder="Enter your first name..."
className="w-full"
rules={{
required: "First name is required",
maxLength: {
value: 24,
message: "First name cannot exceed the limit of 24 characters",
},
}}
render={({ field: { value, onChange, ref } }) => (
<Input
id="first_name"
name="first_name"
type="text"
value={value}
autoFocus={true}
onChange={onChange}
ref={ref}
hasError={Boolean(errors.first_name)}
placeholder="Enter your full name..."
className="w-full focus:border-custom-primary-100 border-onboarding-border-100"
/>
)}
/>
)}
/>
</div>
<div className="space-y-1 text-sm">
<label htmlFor="lastName">Last Name</label>
<Controller
control={control}
name="last_name"
rules={{
required: "Last name is required",
maxLength: {
value: 24,
message: "Last name cannot exceed the limit of 24 characters",
},
}}
render={({ field: { value, onChange, ref } }) => (
<Input
id="last_name"
name="last_name"
type="text"
value={value}
onChange={onChange}
ref={ref}
hasError={Boolean(errors.last_name)}
placeholder="Enter your last name..."
className="w-full"
/>
)}
/>
</div>
<div className="space-y-1 text-sm">
<span>What{"'"}s your role?</span>
<div className="w-full">
</div>
</div>
<div className="mt-14 mb-10">
<Controller
name="role"
control={control}
rules={{ required: "This field is required" }}
name="first_name"
render={({ field: { value } }) => (
<p className="font-medium text-onboarding-text-200 text-xl sm:text-2xl p-0">
And how will you use Plane{value.length>0?", ":""}{value}?
</p>
)}
/>
<p className="font-medium text-onboarding-text-300 text-sm my-3">Choose just one</p>
<Controller
control={control}
name="use_case"
render={({ field: { value, onChange } }) => (
<CustomSelect
value={value}
onChange={(val: any) => onChange(val)}
label={value ? value.toString() : <span className="text-custom-text-400">Select your role...</span>}
input
width="w-full"
>
{USER_ROLES.map((item) => (
<CustomSelect.Option key={item.value} value={item.value}>
{item.label}
</CustomSelect.Option>
<div className="flex flex-wrap break-all overflow-auto">
{useCases.map((useCase) => (
<div
className={`border mb-3 hover:cursor-pointer hover:bg-onboarding-background-300/30 flex-shrink-0 ${
value === useCase ? "border-custom-primary-100" : "border-onboarding-border-100"
} mr-3 rounded-sm p-3 text-sm font-medium`}
onClick={() => onChange(useCase)}
>
{useCase}
</div>
))}
</CustomSelect>
</div>
)}
/>
{errors.role && <span className="text-sm text-red-500">{errors.role.message}</span>}
</div>
</div>
<div className="space-y-1 text-sm">
<span>What time zone are you in? </span>
<div className="w-full">
<Controller
name="user_timezone"
control={control}
rules={{ required: "This field is required" }}
render={({ field: { value, onChange } }) => (
<CustomSearchSelect
value={value}
label={value ? TIME_ZONES.find((t) => t.value === value)?.label ?? value : "Select a timezone"}
options={timeZoneOptions}
onChange={onChange}
optionsClassName="w-full"
input
/>
)}
/>
{errors?.user_timezone && <span className="text-sm text-red-500">{errors.user_timezone.message}</span>}
</div>
<Button variant="primary" type="submit" size="md" disabled={!isValid} loading={isSubmitting}>
{isSubmitting ? "Updating..." : "Continue"}
</Button>
</form>
<div className="mt-3 flex ml-auto">
<Image src={IssuesSvg} className="w-2/3 h-[w-2/3] object-cover" />
</div>
</div>
<Button variant="primary" type="submit" size="md" disabled={!isValid} loading={isSubmitting}>
{isSubmitting ? "Updating..." : "Continue"}
</Button>
</form>
</div>
);
});

View file

@ -1,67 +1,172 @@
import { useState } from "react";
// ui
import { Button } from "@plane/ui";
import { Button, Input } from "@plane/ui";
// types
import { IUser, IWorkspace, TOnboardingSteps } from "types";
// hooks
import useToast from "hooks/use-toast";
// services
import { WorkspaceService } from "services/workspace.service";
// mobx
import { useMobxStore } from "lib/mobx/store-provider";
// constants
import { CreateWorkspaceForm } from "components/workspace";
import { RESTRICTED_URLS } from "constants/workspace";
// react-hook-form
import { Control, Controller, FieldErrors, UseFormHandleSubmit, UseFormSetValue } from "react-hook-form";
type Props = {
finishOnboarding: () => Promise<void>;
stepChange: (steps: Partial<TOnboardingSteps>) => Promise<void>;
updateLastWorkspace: () => Promise<void>;
user: IUser | undefined;
workspaces: IWorkspace[] | undefined;
control: Control<IWorkspace, any>;
handleSubmit: UseFormHandleSubmit<IWorkspace, undefined>;
errors: FieldErrors<IWorkspace>;
setValue: UseFormSetValue<IWorkspace>;
isSubmitting: boolean;
};
export const Workspace: React.FC<Props> = (props) => {
const { finishOnboarding, stepChange, updateLastWorkspace, user, workspaces } = props;
// services
const workspaceService = new WorkspaceService();
const [defaultValues, setDefaultValues] = useState({
name: "",
slug: "",
organization_size: "",
});
export const Workspace: React.FC<Props> = (props) => {
const { stepChange, user, control, handleSubmit, setValue, errors, isSubmitting } = props;
const [slugError, setSlugError] = useState(false);
const [invalidSlug, setInvalidSlug] = useState(false);
const {
workspace: workspaceStore,
user: { updateCurrentUser },
} = useMobxStore();
const { setToastAlert } = useToast();
const handleCreateWorkspace = async (formData: IWorkspace) => {
if (isSubmitting) return;
const slug = formData.slug.split("/");
formData.slug = slug[slug.length - 1];
await workspaceService
.workspaceSlugCheck(formData.slug)
.then(async (res) => {
if (res.status === true && !RESTRICTED_URLS.includes(formData.slug)) {
setSlugError(false);
await workspaceStore
.createWorkspace(formData)
.then(async (res) => {
setToastAlert({
type: "success",
title: "Success!",
message: "Workspace created successfully.",
});
await workspaceStore.fetchWorkspaces();
await completeStep();
})
.catch(() =>
setToastAlert({
type: "error",
title: "Error!",
message: "Workspace could not be created. Please try again.",
})
);
} else setSlugError(true);
})
.catch(() => {
setToastAlert({
type: "error",
title: "Error!",
message: "Some error occurred while creating workspace. Please try again.",
});
});
};
const completeStep = async () => {
if (!user) return;
if (!user || !workspaceStore.workspaces) return;
const payload: Partial<TOnboardingSteps> = {
workspace_create: true,
workspace_join: true,
};
await stepChange(payload);
await updateLastWorkspace();
};
const secondaryButtonAction = async () => {
if (workspaces && workspaces.length > 0) {
await stepChange({ workspace_create: true, workspace_invite: true, workspace_join: true });
await finishOnboarding();
} else await stepChange({ profile_complete: false, workspace_join: false });
await updateCurrentUser({
last_workspace_id: workspaceStore.workspaces[0]?.id,
});
};
return (
<div className="w-full space-y-7 sm:space-y-10">
<h4 className="text-xl sm:text-2xl font-semibold">Create your workspace</h4>
<div className="sm:w-3/4 md:w-2/5">
<CreateWorkspaceForm
onSubmit={completeStep}
defaultValues={defaultValues}
setDefaultValues={setDefaultValues}
primaryButtonText={{
loading: "Creating...",
default: "Continue",
<form className="mt-5 md:w-2/3" onSubmit={handleSubmit(handleCreateWorkspace)}>
<div className="mb-5">
<p className="text-base text-custom-text-400 mb-1">Name it.</p>
<Controller
control={control}
name="name"
rules={{
required: "Workspace name is required",
validate: (value) =>
/^[\w\s-]*$/.test(value) || `Name can only contain (" "), ( - ), ( _ ) & alphanumeric characters.`,
maxLength: {
value: 80,
message: "Workspace name should not exceed 80 characters",
},
}}
secondaryButton={
workspaces ? (
<Button variant="neutral-primary" onClick={secondaryButtonAction}>
{workspaces.length > 0 ? "Skip & continue" : "Back"}
</Button>
) : undefined
}
render={({ field: { value, ref, onChange } }) => (
<div className="flex items-center relative rounded-md bg-onboarding-background-200">
<Input
id="name"
name="name"
type="text"
value={value}
onChange={(event) => {
onChange(event.target.value);
setValue("name", event.target.value);
if (window && window.location.host) {
const host = window.location.host;
const slug = event.currentTarget.value.split("/");
setValue("slug", `${host}/${slug[slug.length - 1].toLocaleLowerCase().trim().replace(/ /g, "-")}`);
}
}}
placeholder="Enter workspace name..."
ref={ref}
hasError={Boolean(errors.name)}
className="w-full h-[46px] text-base placeholder:text-custom-text-400/50 placeholder:text-base border-onboarding-border-100"
/>
</div>
)}
/>
{errors.name && <span className="text-sm text-red-500">{errors.name.message}</span>}
<p className="text-base text-custom-text-400 mt-4 mb-1">You can edit the slug.</p>
<Controller
control={control}
name="slug"
render={({ field: { value, onChange, ref } }) => (
<div className="flex items-center relative rounded-md bg-onboarding-background-200">
<Input
id="slug"
name="slug"
type="text"
prefix="asdasdasdas"
value={value.toLocaleLowerCase().trim().replace(/ /g, "-")}
onChange={(e) => {
const host = window.location.host;
const slug = e.currentTarget.value.split("/");
/^[a-zA-Z0-9_-]+$/.test(slug[slug.length - 1]) ? setInvalidSlug(false) : setInvalidSlug(true);
setValue("slug", `${host}/${slug[slug.length - 1].toLocaleLowerCase().trim().replace(/ /g, "-")}`);
}}
ref={ref}
hasError={Boolean(errors.slug)}
className="w-full h-[46px] border-onboarding-border-100"
/>
</div>
)}
/>
{slugError && <span className="-mt-3 text-sm text-red-500">Workspace URL is already taken!</span>}
{invalidSlug && (
<span className="text-sm text-red-500">{`URL can only contain ( - ), ( _ ) & alphanumeric characters.`}</span>
)}
</div>
</div>
<Button variant="primary" type="submit" size="md">
{isSubmitting ? "Creating..." : "Make it live"}
</Button>
</form>
);
};