|
1 | | -import {PageParams} from "@/types/next"; |
2 | | -import {Page, PageActions, PageContent, PageHeader, PageTitle} from "@/features/layout/page"; |
3 | | -import {currentUser} from "@/lib/auth/current-user"; |
4 | | -import {getActiveMember, getOrganization} from "@/lib/auth/auth"; |
5 | | -import {notFound} from "next/navigation"; |
6 | | -import {Metadata} from "next"; |
7 | | -import {OrganizationTabs} from "@/components/wrappers/dashboard/organization/tabs/organization-tabs"; |
8 | | -import {getOrganizationChannels} from "@/db/services/notification-channel"; |
9 | | -import {computeOrganizationPermissions} from "@/lib/acl/organization-acl"; |
10 | | -import {getOrganizationStorageChannels} from "@/db/services/storage-channel"; |
11 | | -import {DeleteOrganizationButton} from "@/components/wrappers/dashboard/organization/delete-organization-button"; |
12 | | -import {EditOrganizationDialog} from "@/features/organization/components/edit-organization.dialog"; |
13 | | -import {Button} from "@/components/ui/button"; |
14 | | -import {GearIcon} from "@radix-ui/react-icons"; |
15 | | -import {db} from "@/db"; |
16 | | -import {isNull} from "drizzle-orm"; |
| 1 | +import { PageParams } from "@/types/next"; |
| 2 | +import { |
| 3 | + Page, |
| 4 | + PageActions, |
| 5 | + PageContent, |
| 6 | + PageHeader, |
| 7 | + PageTitle, |
| 8 | +} from "@/features/layout/page"; |
| 9 | +import { currentUser } from "@/lib/auth/current-user"; |
| 10 | +import { getActiveMember, getOrganization } from "@/lib/auth/auth"; |
| 11 | +import { notFound } from "next/navigation"; |
| 12 | +import { Metadata } from "next"; |
| 13 | +import { OrganizationTabs } from "@/components/wrappers/dashboard/organization/tabs/organization-tabs"; |
| 14 | +import { getOrganizationChannels } from "@/db/services/notification-channel"; |
| 15 | +import { computeOrganizationPermissions } from "@/lib/acl/organization-acl"; |
| 16 | +import { getOrganizationStorageChannels } from "@/db/services/storage-channel"; |
| 17 | +import { DeleteOrganizationButton } from "@/components/wrappers/dashboard/organization/delete-organization-button"; |
| 18 | +import { EditOrganizationDialog } from "@/features/organization/components/edit-organization.dialog"; |
| 19 | +import { db } from "@/db"; |
| 20 | +import { isNull } from "drizzle-orm"; |
17 | 21 | import * as drizzleDb from "@/db"; |
18 | | -import {eq} from "drizzle-orm"; |
| 22 | +import { eq } from "drizzle-orm"; |
19 | 23 |
|
20 | 24 | export const metadata: Metadata = { |
21 | | - title: "Settings", |
| 25 | + title: "Settings", |
22 | 26 | }; |
23 | 27 |
|
24 | 28 | export default async function RoutePage(props: PageParams<{ slug: string }>) { |
25 | | - const organization = await getOrganization({}); |
26 | | - const user = await currentUser(); |
27 | | - const activeMember = await getActiveMember() |
| 29 | + const organization = await getOrganization({}); |
| 30 | + const user = await currentUser(); |
| 31 | + const activeMember = await getActiveMember(); |
28 | 32 |
|
29 | | - if (!organization || !activeMember || !user) { |
30 | | - notFound(); |
31 | | - } |
| 33 | + if (!organization || !activeMember || !user) { |
| 34 | + notFound(); |
| 35 | + } |
32 | 36 |
|
33 | | - const notificationChannels = await getOrganizationChannels(organization.id) |
34 | | - const storageChannels = await getOrganizationStorageChannels(organization.id) |
35 | | - const permissions = computeOrganizationPermissions(activeMember); |
| 37 | + const notificationChannels = await getOrganizationChannels(organization.id); |
| 38 | + const storageChannels = await getOrganizationStorageChannels(organization.id); |
| 39 | + const permissions = computeOrganizationPermissions(activeMember); |
36 | 40 |
|
37 | | - const users = await db.query.user.findMany({ |
38 | | - where: (fields) => isNull(fields.deletedAt) |
39 | | - }); |
| 41 | + const users = await db.query.user.findMany({ |
| 42 | + where: (fields) => isNull(fields.deletedAt), |
| 43 | + }); |
40 | 44 |
|
41 | | - const organizationWithMembers = await db.query.organization.findFirst({ |
42 | | - where: eq(drizzleDb.schemas.organization.id, organization.id), |
| 45 | + const organizationWithMembers = await db.query.organization.findFirst({ |
| 46 | + where: eq(drizzleDb.schemas.organization.id, organization.id), |
| 47 | + with: { |
| 48 | + members: { |
43 | 49 | with: { |
44 | | - members: { |
45 | | - with: { |
46 | | - user: true |
47 | | - } |
48 | | - } |
49 | | - } |
50 | | - }); |
| 50 | + user: true, |
| 51 | + }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + }); |
51 | 55 |
|
52 | | - if (!organizationWithMembers) notFound(); |
| 56 | + if (!organizationWithMembers) notFound(); |
53 | 57 |
|
54 | | - return ( |
55 | | - <Page> |
56 | | - <PageHeader> |
57 | | - <PageTitle className="flex flex-col md:flex-row items-center justify-between w-full "> |
58 | | - <div className="min-w-full md:min-w-fit "> |
59 | | - Organization settings |
60 | | - </div> |
61 | | - <div className="flex items-center gap-2 md:justify-between w-full "> |
62 | | - <div className="flex items-center gap-2"> |
63 | | - {permissions.canManageSettings && organization.slug !== "default" && ( |
64 | | - <EditOrganizationDialog |
65 | | - organization={organizationWithMembers} |
66 | | - users={users} |
67 | | - currentUser={user} |
68 | | - /> |
69 | | - )} |
70 | | - </div> |
71 | | - <div className="flex items-center gap-2"> |
72 | | - {permissions.canManageDangerZone && organization.slug !== "default" && ( |
73 | | - <DeleteOrganizationButton organizationSlug={organization.slug}/> |
74 | | - )} |
75 | | - </div> |
76 | | - </div> |
77 | | - </PageTitle> |
78 | | - </PageHeader> |
79 | | - <PageContent> |
80 | | - <OrganizationTabs |
81 | | - activeMember={activeMember} |
82 | | - organization={organization} |
83 | | - notificationChannels={notificationChannels} |
84 | | - storageChannels={storageChannels} |
85 | | - /> |
86 | | - </PageContent> |
87 | | - </Page> |
88 | | - ) |
| 58 | + return ( |
| 59 | + <Page> |
| 60 | + <PageHeader> |
| 61 | + <PageTitle className="flex flex-col md:flex-row items-center justify-between w-full "> |
| 62 | + <div className="min-w-full md:min-w-fit ">Organization settings</div> |
| 63 | + <div className="flex items-center gap-2 md:justify-between w-full "> |
| 64 | + <div className="flex items-center gap-2"> |
| 65 | + {permissions.canManageSettings && |
| 66 | + organization.slug !== "default" && ( |
| 67 | + <EditOrganizationDialog |
| 68 | + organization={organizationWithMembers} |
| 69 | + users={users} |
| 70 | + currentUser={user} |
| 71 | + /> |
| 72 | + )} |
| 73 | + </div> |
| 74 | + <div className="flex items-center gap-2"> |
| 75 | + {permissions.canManageDangerZone && |
| 76 | + organization.slug !== "default" && ( |
| 77 | + <DeleteOrganizationButton |
| 78 | + organizationSlug={organization.slug} |
| 79 | + /> |
| 80 | + )} |
| 81 | + </div> |
| 82 | + </div> |
| 83 | + </PageTitle> |
| 84 | + </PageHeader> |
| 85 | + <PageContent> |
| 86 | + <OrganizationTabs |
| 87 | + activeMember={activeMember} |
| 88 | + organization={organization} |
| 89 | + notificationChannels={notificationChannels} |
| 90 | + storageChannels={storageChannels} |
| 91 | + /> |
| 92 | + </PageContent> |
| 93 | + </Page> |
| 94 | + ); |
89 | 95 | } |
0 commit comments