-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎮
WOR-7
sign-in/out & create/switch workspace
- Loading branch information
1 parent
29dadca
commit 9074ff6
Showing
22 changed files
with
629 additions
and
40 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
apps/playground/src/app/(platform)/(auth)/onboarding/_components/card.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* eslint-disable jsx-a11y/click-events-have-key-events */ | ||
"use client"; | ||
|
||
import Image from "next/image"; | ||
|
||
import { cn } from "@swy/ui/lib"; | ||
|
||
export interface CardProps { | ||
id: number; | ||
checked: boolean; | ||
image: string; | ||
title: string; | ||
description: string; | ||
onClick?: () => void; | ||
} | ||
|
||
export const Card = ({ | ||
id, | ||
checked, | ||
image, | ||
title, | ||
description, | ||
onClick, | ||
}: CardProps) => { | ||
return ( | ||
<div | ||
id={`${id}`} | ||
role="button" | ||
tabIndex={0} | ||
className={cn( | ||
"relative m-3 h-[280px] w-[230px] cursor-pointer select-none items-center justify-center whitespace-normal rounded-md border border-primary/20 bg-white py-10 text-center text-sm/[1.2] opacity-70 hover:opacity-100", | ||
checked && "border-2 border-blue opacity-100", | ||
)} | ||
onClick={onClick} | ||
> | ||
<Image | ||
src="https://www.notion.so/images/onboarding/unchecked.svg" | ||
alt="" | ||
className={cn("absolute right-3 top-3", checked && "hidden")} | ||
height={24} | ||
width={24} | ||
/> | ||
<Image | ||
src="https://www.notion.so/images/onboarding/checked.svg" | ||
alt="" | ||
className={cn("absolute right-3 top-3", !checked && "hidden")} | ||
height={24} | ||
width={24} | ||
/> | ||
<div className="flex h-[90px] justify-center"> | ||
<Image src={image} alt="" className="h-full" /> | ||
</div> | ||
<div className="m-4 flex-grow basis-full"> | ||
<header className="mt-[30px] text-lg font-semibold text-black"> | ||
{title} | ||
</header> | ||
<p className="mb-2 mt-3 text-sm/snug text-black/70">{description}</p> | ||
</div> | ||
</div> | ||
); | ||
}; |
137 changes: 137 additions & 0 deletions
137
apps/playground/src/app/(platform)/(auth)/onboarding/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
"use client"; | ||
|
||
import { useEffect, useState } from "react"; | ||
import { useRouter } from "next/navigation"; | ||
import { v4 } from "uuid"; | ||
|
||
import { useBoundStore } from "@swy/notion"; | ||
import { Button } from "@swy/ui/shadcn"; | ||
import { Plan, Role } from "@swy/validators"; | ||
|
||
import { WorkspaceModel } from "~/db"; | ||
import { useAppActions, useAppState, useMockDB } from "~/hooks"; | ||
import { Card, type CardProps } from "./_components/card"; | ||
|
||
const data: Omit<CardProps, "checked">[] = [ | ||
{ | ||
id: 0, | ||
image: | ||
"https://www.notion.so/images/onboarding/team-features-illustration.png", | ||
title: "For my team", | ||
description: "Collaborate on your docs, projects, and wikis.", | ||
}, | ||
{ | ||
id: 1, | ||
image: "https://www.notion.so/images/onboarding/use-case-note.png", | ||
title: "For personal use", | ||
description: "Write better. Think more clearly. Stay organized.", | ||
}, | ||
{ | ||
id: 2, | ||
image: "https://www.notion.so/images/onboarding/use-case-wiki.png", | ||
title: "For school", | ||
description: "Keep your notes, research, and tasks all in one place.", | ||
}, | ||
]; | ||
|
||
export default function Page() { | ||
const [checked, setChecked] = useState(-1); | ||
const router = useRouter(); | ||
const { updateDB } = useMockDB(); | ||
const [isSignedIn, accountId] = useAppState((state) => [ | ||
state.isSignedIn, | ||
state.userId, | ||
]); | ||
const { selectWorkspace } = useAppActions(); | ||
const addWorkspace = useBoundStore((state) => state.addWorkspace); | ||
|
||
const createWorkspace = async () => { | ||
if (!accountId) { | ||
router.push("/sign-in"); | ||
return; | ||
} | ||
const wid = v4(); | ||
const w: WorkspaceModel = { | ||
id: wid, | ||
name: "New Workspace", | ||
createdBy: accountId, | ||
domain: `workspace-${accountId.slice(0, 5)}`, | ||
inviteToken: wid, | ||
plan: Plan.FREE, | ||
icon: { type: "text", text: "N" }, | ||
lastEditedAt: Date.now(), | ||
}; | ||
await updateDB("workspaces", { [wid]: w }); | ||
const mem = { | ||
id: v4(), | ||
accountId, | ||
workspaceId: w.id, | ||
joinedAt: Date.now(), | ||
role: Role.OWNER, | ||
}; | ||
await updateDB("memberships", [mem]); | ||
addWorkspace({ | ||
id: wid, | ||
name: w.name, | ||
icon: w.icon ?? { type: "text", text: w.name }, | ||
members: 1, | ||
plan: w.plan, | ||
role: mem.role, | ||
}); | ||
console.log(`create success, redirecting to ${wid}`); | ||
selectWorkspace(w.id); | ||
}; | ||
|
||
useEffect(() => { | ||
if (!isSignedIn) router.push("/sign-in"); | ||
}, [isSignedIn, router]); | ||
|
||
return ( | ||
<> | ||
<div className="flex min-h-screen flex-col justify-center"> | ||
<div className="relative mx-auto max-w-[520px] py-8 text-center"> | ||
<div> | ||
<div className="font-sans text-3xl/tight font-semibold"> | ||
How are you planning to use Notion? | ||
</div> | ||
<div className="pt-0.5 text-lg/tight font-normal text-secondary dark:text-secondary-dark"> | ||
We’ll streamline your setup experience accordingly. | ||
</div> | ||
</div> | ||
</div> | ||
<div className="flex flex-col items-center pb-8"> | ||
<div className="flex flex-col items-center justify-center"> | ||
<div className="mb-8 mt-2.5 inline-flex w-full justify-center"> | ||
{data.map((props) => ( | ||
<Card | ||
key={props.id} | ||
{...props} | ||
checked={checked === props.id} | ||
onClick={() => setChecked(props.id)} | ||
/> | ||
))} | ||
</div> | ||
<Button | ||
variant="blue" | ||
size="sm" | ||
className="w-[280px]" | ||
disabled={!(checked in ([0, 1, 2] as const))} | ||
onClick={() => void createWorkspace()} | ||
> | ||
Continue | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
<Button | ||
variant="hint" | ||
size="sm" | ||
tabIndex={0} | ||
className="absolute right-[18px] top-[18px] text-primary dark:text-primary/80" | ||
onClick={() => router.back()} | ||
> | ||
Cancel | ||
</Button> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
apps/playground/src/app/(platform)/(core)/home/[workspaceId]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"use client"; | ||
|
||
import Image from "next/image"; | ||
import { PlusCircle } from "lucide-react"; | ||
|
||
import { useBoundStore } from "@swy/notion"; | ||
import { Button } from "@swy/ui/shadcn"; | ||
|
||
interface Params { | ||
params: { workspaceId: string }; | ||
} | ||
|
||
const HomePage = ({ params: _ }: Params) => { | ||
const activeWorkspace = useBoundStore( | ||
(state) => state.workspaces[state.activeWorkspace ?? ""], | ||
); | ||
/** Action */ | ||
const onSubmit = () => { | ||
// TODO create doc | ||
}; | ||
|
||
return ( | ||
<div className="flex h-full flex-col items-center justify-center space-y-4"> | ||
<Image | ||
src="/empty.png" | ||
height="300" | ||
width="300" | ||
alt="Empty" | ||
className="dark:hidden" | ||
/> | ||
<Image | ||
src="/empty-dark.png" | ||
height="300" | ||
width="300" | ||
alt="Empty" | ||
className="hidden dark:block" | ||
/> | ||
<h2 className="text-lg font-medium"> | ||
Welcome to {activeWorkspace?.name ?? "WorXpace"} | ||
</h2> | ||
<form action={onSubmit}> | ||
<Button type="submit"> | ||
<PlusCircle className="mr-2 size-4" /> | ||
Create a note | ||
</Button> | ||
</form> | ||
</div> | ||
); | ||
}; | ||
|
||
export default HomePage; |
Oops, something went wrong.