-
-
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.
🔄 Merge pull request #10 from steeeee0223/feature/worxpace
Setup sidebar & actions (create/get docs)
- Loading branch information
Showing
19 changed files
with
436 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"use server"; | ||
|
||
import { revalidatePath } from "next/cache"; | ||
|
||
import { type Document } from "@acme/prisma"; | ||
import { createSafeAction, type ActionHandler } from "@acme/ui/lib"; | ||
import { CreateDocument, type CreateDocumentInput } from "@acme/validators"; | ||
|
||
import { | ||
createDocument as $create, | ||
createAuditLog, | ||
fetchClient, | ||
UnauthorizedError, | ||
} from "~/lib"; | ||
|
||
const handler: ActionHandler<CreateDocumentInput, Document> = async (data) => { | ||
let result; | ||
|
||
try { | ||
const { userId, orgId, path } = fetchClient(); | ||
result = await $create({ ...data, userId, orgId }); | ||
/** Activity Log */ | ||
await createAuditLog( | ||
{ title: result.title, entityId: result.id, type: "DOCUMENT" }, | ||
"CREATE", | ||
); | ||
revalidatePath(path); | ||
} catch (error) { | ||
if (error instanceof UnauthorizedError) return { error: "Unauthorized" }; | ||
console.log(`ERROR`, error); | ||
return { error: "Failed to create document." }; | ||
} | ||
|
||
return { data: result }; | ||
}; | ||
|
||
export const createDocument = createSafeAction(CreateDocument, handler); |
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 @@ | ||
export * from "./create-document" |
63 changes: 60 additions & 3 deletions
63
apps/worxpace/src/app/(platform)/(tools)/[role]/[clientId]/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
42 changes: 42 additions & 0 deletions
42
apps/worxpace/src/app/(platform)/(tools)/_components/doc-list.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,42 @@ | ||
import { OrganizationSwitcher } from "@clerk/nextjs"; | ||
|
||
interface DocListProps { | ||
isMobile?: boolean; | ||
} | ||
|
||
const DocList = ({ isMobile }: DocListProps) => { | ||
return ( | ||
<> | ||
<div> | ||
<OrganizationSwitcher | ||
afterSelectPersonalUrl="/personal/:id" | ||
afterCreateOrganizationUrl="/organization/:id" | ||
afterSelectOrganizationUrl="/organization/:id" | ||
afterLeaveOrganizationUrl="/select-role" | ||
appearance={{ | ||
elements: { | ||
rootBox: { | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
borderRadius: 6, | ||
padding: "14px 8px", | ||
}, | ||
avatarBox: { | ||
borderRadius: 9999, | ||
height: "20px", | ||
width: "20px", | ||
}, | ||
organizationSwitcherPopoverCard: { | ||
zIndex: 99999, | ||
}, | ||
}, | ||
}} | ||
/> | ||
</div> | ||
<div className="mt-4">Doc Items</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default DocList; |
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
98 changes: 98 additions & 0 deletions
98
apps/worxpace/src/app/(platform)/(tools)/_components/user-items.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,98 @@ | ||
"use client"; | ||
|
||
import { SignOutButton, useOrganizationList, useUser } from "@clerk/nextjs"; | ||
import { ChevronsLeftRight } from "lucide-react"; | ||
|
||
import { | ||
Avatar, | ||
AvatarImage, | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuSeparator, | ||
DropdownMenuTrigger, | ||
} from "@acme/ui/components"; | ||
import { cn } from "@acme/ui/lib"; | ||
|
||
import { theme } from "~/constants/theme"; | ||
|
||
interface UserItemProps { | ||
name?: string | null; | ||
imageUrl?: string | null; | ||
} | ||
const UserItem = ({ name, imageUrl }: UserItemProps) => { | ||
return ( | ||
<div className={theme.flex.gap2}> | ||
<div className="rounded-md bg-secondary p-1"> | ||
<Avatar className="h-8 w-8"> | ||
<AvatarImage src={imageUrl ?? undefined} /> | ||
</Avatar> | ||
</div> | ||
<div className="space-y-1"> | ||
<p className="line-clamp-1 text-sm">{name ?? "User"}'s WorXpace</p> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
/** @deprecated */ | ||
export const UserItems = () => { | ||
const { user } = useUser(); | ||
const { userMemberships } = useOrganizationList({ | ||
userMemberships: { infinite: true }, | ||
}); | ||
|
||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<div | ||
role="button" | ||
className={cn( | ||
theme.flex.center, | ||
"w-full p-3 text-sm hover:bg-primary/5", | ||
)} | ||
> | ||
<div className={cn(theme.flex.gap2, "max-w-[150px]")}> | ||
<Avatar className="h-5 w-5"> | ||
<AvatarImage src={user?.imageUrl} /> | ||
</Avatar> | ||
<span className="line-clamp-1 text-start font-medium"> | ||
{user?.fullName} | ||
</span> | ||
</div> | ||
<ChevronsLeftRight | ||
className={cn( | ||
theme.size.icon, | ||
"ml-2 rotate-90 text-muted-foreground", | ||
)} | ||
/> | ||
</div> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent | ||
className="z-[99999] w-80" | ||
align="start" | ||
alignOffset={11} | ||
forceMount | ||
> | ||
<div className="flex flex-col space-y-4 p-2"> | ||
<p className="text-xs font-medium leading-none text-muted-foreground"> | ||
{user?.emailAddresses[0].emailAddress} | ||
</p> | ||
<UserItem name={user?.fullName} imageUrl={user?.imageUrl} /> | ||
{userMemberships.data?.map( | ||
({ organization: { id, name, imageUrl } }) => ( | ||
<UserItem key={id} name={name} imageUrl={imageUrl} /> | ||
), | ||
)} | ||
</div> | ||
<DropdownMenuSeparator /> | ||
<DropdownMenuItem | ||
asChild | ||
className="w-full cursor-pointer text-muted-foreground" | ||
> | ||
<SignOutButton>Log out</SignOutButton> | ||
</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
}; |
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,22 @@ | ||
"use server"; | ||
|
||
import { worxpace as db, type Document } from "@acme/prisma"; | ||
import { CreateDocumentInput } from "@acme/validators"; | ||
|
||
export const createDocument = async ( | ||
data: CreateDocumentInput & { userId: string; orgId: string | null }, | ||
): Promise<Document> => | ||
await db.document.create({ | ||
data: { ...data, isArchived: false, isPublished: false }, | ||
}); | ||
|
||
export const fetchDocuments = async ( | ||
userId: string, | ||
orgId: string | null, | ||
isArchived?: boolean, | ||
parentId?: string | null, | ||
): Promise<Document[]> => | ||
await db.document.findMany({ | ||
where: { userId, orgId, parentId, isArchived }, | ||
orderBy: { createdAt: "desc" }, | ||
}); |
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,11 @@ | ||
export class UnauthorizedError extends Error { | ||
constructor() { | ||
super("Unauthorized"); | ||
} | ||
} | ||
|
||
export class NotFound extends Error { | ||
constructor() { | ||
super("Not Found"); | ||
} | ||
} |
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 +1,5 @@ | ||
export * from "./documents"; | ||
export * from "./errors"; | ||
export * from "./logs"; | ||
export * from "./types"; | ||
export * from "./utils"; |
Oops, something went wrong.