-
-
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.
- Loading branch information
1 parent
b66b87a
commit 884a690
Showing
135 changed files
with
2,739 additions
and
1,732 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -16,12 +16,6 @@ export default meta; | |
type Story = StoryObj<typeof meta>; | ||
|
||
const mockSettings: SettingsStore = { | ||
user: { | ||
id: "1", | ||
name: "John Doe", | ||
email: "[email protected]", | ||
imageUrl: "https://github.com/shadcn.png", | ||
}, | ||
workspace: { | ||
id: "fake-workspace-id-12345", | ||
name: "John's Private", | ||
|
@@ -32,6 +26,8 @@ const mockSettings: SettingsStore = { | |
avatarUrl: "https://github.com/shadcn.png", | ||
preferredName: "John Doe", | ||
email: "[email protected]", | ||
id: "fake-account-id-123", | ||
name: "John Wick", | ||
}, | ||
}; | ||
|
||
|
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
53 changes: 32 additions & 21 deletions
53
apps/storybook/src/stories/notion/workspace-provider/utils.ts
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 |
---|---|---|
@@ -1,30 +1,41 @@ | ||
import type { UserState, Workspace } from "@acme/ui/notion"; | ||
|
||
const createWorkspaceData = ( | ||
name: string, | ||
id: number | string, | ||
user: UserState, | ||
): Workspace => ({ | ||
id: `dummy-workspace-${id}`, | ||
name, | ||
icon: "🎑", | ||
owner: user.name, | ||
ownerId: user.id, | ||
members: [], | ||
}); | ||
|
||
export const user: UserState = { | ||
id: "dummy-user", | ||
name: "Steve", | ||
email: "[email protected]", | ||
isDarkMode: false, | ||
profilePicture: { | ||
url: "", | ||
}, | ||
}; | ||
export const workspaces: Workspace[] = [ | ||
createWorkspaceData("Steve's Workspace", `personal`, user), | ||
createWorkspaceData("Workspace 1", 1, user), | ||
createWorkspaceData("Workspace 2", 2, user), | ||
createWorkspaceData("Workspace 3", 3, user), | ||
{ | ||
id: "dummy-workspace-personal", | ||
name: "John's Workspace", | ||
icon: { type: "lucide", name: "activity", color: "#CB912F" }, | ||
members: 1, | ||
plan: "Education Plus Plan", | ||
role: "owner", | ||
}, | ||
{ | ||
id: "dummy-workspace-1", | ||
name: "Workspace 1", | ||
icon: { type: "lucide", name: "briefcase", color: "#337EA9" }, | ||
members: 3, | ||
plan: "Free Plan", | ||
role: "owner", | ||
}, | ||
{ | ||
id: "dummy-workspace-2", | ||
name: "Workspace 2", | ||
icon: { type: "emoji", emoji: "🎨" }, | ||
members: 2, | ||
plan: "Business Plan", | ||
role: "member", | ||
}, | ||
{ | ||
id: "dummy-workspace-3", | ||
name: "Workspace 3", | ||
icon: { type: "emoji", emoji: "🚧" }, | ||
members: 8, | ||
plan: "Enterprise Plan", | ||
role: "guest", | ||
}, | ||
]; |
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
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 |
---|---|---|
@@ -1,39 +1,49 @@ | ||
"use server"; | ||
|
||
import { revalidatePath } from "next/cache"; | ||
import type { MutationFetcher } from "swr/mutation"; | ||
|
||
import type { Document, ENTITY_TYPE } from "@acme/prisma"; | ||
import type { ENTITY_TYPE } from "@acme/prisma"; | ||
import { type Modified } from "@acme/ui/lib"; | ||
import { DeleteDocument, type DeleteDocumentInput } from "@acme/validators"; | ||
|
||
import { | ||
account, | ||
auditLogs, | ||
createMutationFetcher, | ||
documents, | ||
fetchClient, | ||
UnauthorizedError, | ||
type Action, | ||
type DetailedDocument, | ||
type DocumentsKey, | ||
} from "~/lib"; | ||
|
||
const handler: Action<DeleteDocumentInput, Modified<Document>> = async ( | ||
_key, | ||
{ arg }, | ||
) => { | ||
try { | ||
const { userId, orgId } = fetchClient(); | ||
const result = await documents.archive({ ...arg, userId, orgId }); | ||
/** Activity Log */ | ||
const type = result.item.type.toUpperCase() as ENTITY_TYPE; | ||
await auditLogs.create( | ||
{ title: result.item.title, entityId: arg.id, type }, | ||
"DELETE", | ||
); | ||
revalidatePath(`/documents/${arg.id}`); | ||
return result; | ||
} catch (error) { | ||
if (error instanceof UnauthorizedError) throw error; | ||
throw new Error("Failed to archive document."); | ||
} | ||
}; | ||
const handler = createMutationFetcher( | ||
DeleteDocument, | ||
async (workspaceId, { arg }) => { | ||
try { | ||
const { clerkId } = fetchClient(); | ||
const inWorkspace = await account.isInWorkspace({ clerkId, workspaceId }); | ||
if (!inWorkspace) throw new UnauthorizedError(); | ||
const result = await documents.archive(arg); | ||
/** Activity Log */ | ||
const type = result.item.type.toUpperCase() as ENTITY_TYPE; | ||
await auditLogs.create({ | ||
entity: { title: result.item.title, entityId: arg.id, type }, | ||
action: "DELETE", | ||
accountId: arg.accountId, | ||
}); | ||
revalidatePath(`/documents/${arg.id}`); | ||
return result; | ||
} catch (error) { | ||
if (error instanceof UnauthorizedError) throw error; | ||
throw new Error("Failed to archive document."); | ||
} | ||
}, | ||
); | ||
|
||
export const archiveDocument = createMutationFetcher(DeleteDocument, handler); | ||
export const archiveDocument: MutationFetcher< | ||
Modified<DetailedDocument>, | ||
DocumentsKey, | ||
DeleteDocumentInput | ||
> = ({ workspaceId }, data) => handler(workspaceId, data); |
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
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,28 @@ | ||
"use server"; | ||
|
||
import type { MutationFetcher } from "swr/mutation"; | ||
|
||
import type { Account } from "@acme/prisma"; | ||
import { CreateAccount, type CreateAccountInput } from "@acme/validators"; | ||
|
||
import { account, createMutationFetcher, UnauthorizedError } from "~/lib"; | ||
|
||
const handler = createMutationFetcher( | ||
CreateAccount, | ||
async (clerkId, { arg }) => { | ||
try { | ||
const data = await account.get(clerkId); | ||
if (data) return data; | ||
return await account.create(arg); | ||
} catch (error) { | ||
if (error instanceof UnauthorizedError) throw error; | ||
throw new Error("Failed to create account."); | ||
} | ||
}, | ||
); | ||
|
||
export const createAccount: MutationFetcher< | ||
Account, | ||
{ type: "settings"; clerkId: string }, | ||
CreateAccountInput | ||
> = ({ clerkId }, data) => handler(clerkId, data); |
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
Oops, something went wrong.