@ploykit/ui 0.1.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +183 -23
- package/dist/AppProviders.d.ts +15 -0
- package/dist/AppProviders.js +15 -0
- package/dist/components/ConfirmDialog.js +8 -2
- package/dist/components/CronInput.js +2 -2
- package/dist/components/DataTable.d.ts +12 -3
- package/dist/components/DataTable.js +7 -3
- package/dist/components/ErrorBoundary.js +1 -1
- package/dist/components/ImpersonationBanner.js +1 -1
- package/dist/components/NotificationBell.js +5 -5
- package/dist/components/OnboardingChecklist.js +3 -3
- package/dist/components/Page.js +1 -1
- package/dist/components/ReauthDialog.d.ts +15 -0
- package/dist/components/ReauthDialog.js +42 -0
- package/dist/components/SecretModal.d.ts +8 -1
- package/dist/components/SecretModal.js +6 -3
- package/dist/components/SettingsCard.js +2 -2
- package/dist/components/SiteBannerLayer.js +1 -1
- package/dist/components/StatusBadge.d.ts +4 -0
- package/dist/components/StatusBadge.js +7 -0
- package/dist/components/UserMenu.js +2 -2
- package/dist/components/WorkspaceSwitcher.js +4 -4
- package/dist/components/ui/alert-dialog.d.ts +2 -2
- package/dist/components/ui/alert-dialog.js +10 -9
- package/dist/components/ui/avatar.js +3 -2
- package/dist/components/ui/badge.d.ts +7 -0
- package/dist/components/ui/badge.js +33 -0
- package/dist/components/ui/breadcrumb.js +7 -7
- package/dist/components/ui/button.d.ts +8 -0
- package/dist/components/ui/button.js +34 -0
- package/dist/components/ui/card.d.ts +2 -4
- package/dist/components/ui/card.js +7 -7
- package/dist/components/ui/checkbox.js +3 -2
- package/dist/components/ui/dialog.d.ts +22 -14
- package/dist/components/ui/dialog.js +40 -25
- package/dist/components/ui/dropdown-menu.js +50 -0
- package/dist/components/ui/empty.d.ts +7 -9
- package/dist/components/ui/empty.js +6 -9
- package/dist/components/ui/field.js +10 -9
- package/dist/components/ui/input.d.ts +3 -0
- package/dist/components/ui/input.js +7 -0
- package/dist/components/ui/popover.js +3 -2
- package/dist/components/ui/progress.js +2 -1
- package/dist/components/ui/select.d.ts +20 -1
- package/dist/components/ui/select.js +28 -7
- package/dist/components/ui/separator.js +1 -0
- package/dist/components/ui/sheet.d.ts +9 -1
- package/dist/components/ui/sheet.js +11 -4
- package/dist/components/ui/sidebar.d.ts +2 -2
- package/dist/components/ui/sidebar.js +25 -34
- package/dist/components/ui/skeleton.d.ts +1 -2
- package/dist/components/ui/switch.js +1 -1
- package/dist/components/ui/tabs.js +3 -3
- package/dist/components/ui/textarea.d.ts +9 -0
- package/dist/components/ui/textarea.js +12 -0
- package/dist/components/ui/tooltip.js +1 -1
- package/dist/index.d.ts +10 -40
- package/dist/index.js +10 -26
- package/dist/layouts/AppShell.d.ts +1 -1
- package/dist/layouts/AppShell.js +23 -1
- package/dist/layouts/SettingsShell.d.ts +1 -1
- package/dist/layouts/SettingsShell.js +3 -3
- package/dist/pages/LandingPage.js +1 -1
- package/dist/pages/LoginPage.js +7 -7
- package/dist/pages/account/NotificationPreferencesPage.js +2 -2
- package/dist/pages/account/ProfileSettingsPage.js +7 -7
- package/dist/pages/account/SecuritySettingsPage.js +8 -8
- package/dist/pages/account/TokensPage.js +4 -4
- package/dist/pages/admin/AdminSettingsPage.js +5 -5
- package/dist/pages/admin/AdminShell.js +2 -2
- package/dist/pages/admin/AuditPage.js +3 -3
- package/dist/pages/admin/OrdersPage.js +4 -3
- package/dist/pages/admin/OverviewPage.js +4 -4
- package/dist/pages/admin/SSOPage.js +3 -3
- package/dist/pages/admin/UserDetailPage.js +6 -5
- package/dist/pages/admin/UsersPage.js +7 -6
- package/dist/pages/admin/WebhookDeliveriesPage.js +4 -3
- package/dist/pages/admin/WorkspaceDetailPage.js +5 -5
- package/dist/pages/admin/WorkspacesPage.js +4 -4
- package/dist/pages/admin/shared.js +1 -1
- package/dist/pages/auth/ForgotPasswordPage.js +3 -3
- package/dist/pages/auth/InviteAcceptPage.js +4 -4
- package/dist/pages/auth/RegisterPage.js +6 -6
- package/dist/pages/auth/ResetPasswordPage.js +4 -4
- package/dist/pages/auth/VerifyEmailPage.js +4 -4
- package/dist/pages/workspace/BillingPage.js +8 -7
- package/dist/pages/workspace/BillingSuccessPage.js +3 -3
- package/dist/pages/workspace/MembersPage.js +7 -6
- package/dist/pages/workspace/RolePermissionsPage.d.ts +3 -0
- package/dist/pages/workspace/RolePermissionsPage.js +118 -0
- package/dist/pages/workspace/SchedulesPage.js +5 -5
- package/dist/pages/workspace/UsagePage.d.ts +1 -1
- package/dist/pages/workspace/UsagePage.js +2 -2
- package/dist/pages/workspace/WebhooksPage.js +9 -9
- package/dist/pages/workspace/WorkspaceAuditPage.js +3 -3
- package/dist/pages/workspace/WorkspaceGeneralPage.js +7 -7
- package/package.json +9 -5
- package/dist/components/ui/Badge.d.ts +0 -13
- package/dist/components/ui/Badge.js +0 -21
- package/dist/components/ui/Button.d.ts +0 -10
- package/dist/components/ui/Button.js +0 -33
- package/dist/components/ui/Input.d.ts +0 -3
- package/dist/components/ui/Input.js +0 -10
- package/dist/components/ui/menu.js +0 -50
- package/dist/hooks/useApi.d.ts +0 -10
- package/dist/hooks/useApi.js +0 -11
- package/dist/hooks/useAudit.d.ts +0 -39
- package/dist/hooks/useAudit.js +0 -55
- package/dist/hooks/useAuth.d.ts +0 -1
- package/dist/hooks/useAuth.js +0 -4
- package/dist/hooks/useBilling.d.ts +0 -44
- package/dist/hooks/useBilling.js +0 -64
- package/dist/hooks/useLogin.d.ts +0 -10
- package/dist/hooks/useLogin.js +0 -39
- package/dist/hooks/useMembers.d.ts +0 -125
- package/dist/hooks/useMembers.js +0 -127
- package/dist/hooks/useNotificationPrefs.d.ts +0 -20
- package/dist/hooks/useNotificationPrefs.js +0 -42
- package/dist/hooks/usePasswordReset.d.ts +0 -5
- package/dist/hooks/usePasswordReset.js +0 -12
- package/dist/hooks/useSEO.d.ts +0 -6
- package/dist/hooks/useSEO.js +0 -14
- package/dist/hooks/useSessions.d.ts +0 -20
- package/dist/hooks/useSessions.js +0 -38
- package/dist/hooks/useSiteConfig.d.ts +0 -12
- package/dist/hooks/useSiteConfig.js +0 -11
- package/dist/hooks/useTokens.d.ts +0 -36
- package/dist/hooks/useTokens.js +0 -35
- package/dist/hooks/useUsage.d.ts +0 -20
- package/dist/hooks/useUsage.js +0 -21
- package/dist/hooks/useWorkspace.d.ts +0 -26
- package/dist/hooks/useWorkspace.js +0 -32
- package/dist/hooks/useZodForm.d.ts +0 -6
- package/dist/hooks/useZodForm.js +0 -6
- package/dist/hooks/ws.d.ts +0 -4
- package/dist/hooks/ws.js +0 -21
- package/dist/lib/perm.d.ts +0 -2
- package/dist/lib/perm.js +0 -7
- package/dist/lib/ws-query-bridge.d.ts +0 -7
- package/dist/lib/ws-query-bridge.js +0 -35
- package/dist/provider/PloykitProvider.d.ts +0 -50
- package/dist/provider/PloykitProvider.js +0 -240
- package/dist/realtime.d.ts +0 -3
- package/dist/realtime.js +0 -11
- /package/dist/components/ui/{menu.d.ts → dropdown-menu.d.ts} +0 -0
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { type VariantProps } from 'class-variance-authority';
|
|
3
|
-
declare const buttonVariants: (props?: ({
|
|
4
|
-
variant?: "default" | "link" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined;
|
|
5
|
-
size?: "default" | "sm" | "lg" | "icon" | "iconSm" | null | undefined;
|
|
6
|
-
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
7
|
-
export interface ButtonProps extends React.ComponentPropsWithRef<'button'>, VariantProps<typeof buttonVariants> {
|
|
8
|
-
}
|
|
9
|
-
declare function Button({ className, variant, size, ref, ...props }: ButtonProps): React.JSX.Element;
|
|
10
|
-
export { Button, buttonVariants };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { cva } from 'class-variance-authority';
|
|
3
|
-
import { cn } from '../../lib/utils';
|
|
4
|
-
const buttonVariants = cva('inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors ' +
|
|
5
|
-
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ' +
|
|
6
|
-
'disabled:pointer-events-none disabled:opacity-50 ' +
|
|
7
|
-
'[&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0', {
|
|
8
|
-
variants: {
|
|
9
|
-
variant: {
|
|
10
|
-
default: 'bg-primary text-primary-foreground shadow hover:bg-primary/90',
|
|
11
|
-
destructive: 'bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90',
|
|
12
|
-
outline: 'border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground',
|
|
13
|
-
secondary: 'bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80',
|
|
14
|
-
ghost: 'hover:bg-accent hover:text-accent-foreground',
|
|
15
|
-
link: 'text-primary underline-offset-4 hover:underline',
|
|
16
|
-
},
|
|
17
|
-
size: {
|
|
18
|
-
default: 'h-9 px-4 py-2',
|
|
19
|
-
sm: 'h-8 rounded-md px-3 text-xs',
|
|
20
|
-
lg: 'h-10 rounded-md px-8',
|
|
21
|
-
icon: 'h-9 w-9',
|
|
22
|
-
iconSm: 'size-8 rounded-md',
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
defaultVariants: {
|
|
26
|
-
variant: 'default',
|
|
27
|
-
size: 'default',
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
function Button({ className, variant, size, ref, ...props }) {
|
|
31
|
-
return (_jsx("button", { "data-slot": "button", className: cn(buttonVariants({ variant, size, className })), ref: ref, ...props }));
|
|
32
|
-
}
|
|
33
|
-
export { Button, buttonVariants };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { cn } from '../../lib/utils';
|
|
3
|
-
function Input({ className, type, ref, ...props }) {
|
|
4
|
-
return (_jsx("input", { type: type, "data-slot": "input", className: cn('flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors ' +
|
|
5
|
-
'file:border-0 file:bg-transparent file:text-sm file:font-medium ' +
|
|
6
|
-
'placeholder:text-muted-foreground ' +
|
|
7
|
-
'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring ' +
|
|
8
|
-
'disabled:cursor-not-allowed disabled:opacity-50', className), ref: ref, ...props }));
|
|
9
|
-
}
|
|
10
|
-
export { Input };
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Menu as MenuPrimitive } from "@base-ui/react/menu";
|
|
3
|
-
import { CheckIcon, ChevronRightIcon } from "lucide-react";
|
|
4
|
-
import { cn } from "../../lib/utils";
|
|
5
|
-
function DropdownMenu({ ...props }) {
|
|
6
|
-
return _jsx(MenuPrimitive.Root, { "data-slot": "dropdown-menu", ...props });
|
|
7
|
-
}
|
|
8
|
-
function DropdownMenuPortal({ ...props }) {
|
|
9
|
-
return _jsx(MenuPrimitive.Portal, { "data-slot": "dropdown-menu-portal", ...props });
|
|
10
|
-
}
|
|
11
|
-
function DropdownMenuTrigger({ ...props }) {
|
|
12
|
-
return _jsx(MenuPrimitive.Trigger, { "data-slot": "dropdown-menu-trigger", ...props });
|
|
13
|
-
}
|
|
14
|
-
function DropdownMenuContent({ align = "start", alignOffset = 0, side = "bottom", sideOffset = 4, className, ...props }) {
|
|
15
|
-
return (_jsx(MenuPrimitive.Portal, { children: _jsx(MenuPrimitive.Positioner, { className: "isolate z-50 outline-none", align: align, alignOffset: alignOffset, side: side, sideOffset: sideOffset, children: _jsx(MenuPrimitive.Popup, { "data-slot": "dropdown-menu-content", className: cn("relative z-50 max-h-(--available-height) w-(--anchor-width) origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-md bg-popover/70 p-1 text-popover-foreground text-sm shadow-md ring-1 ring-foreground/10 outline-none duration-100 animate-none! before:pointer-events-none before:absolute before:inset-0 before:-z-1 before:rounded-[inherit] before:backdrop-blur-2xl before:backdrop-saturate-150 data-closed:overflow-hidden data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 **:data-[slot$=-item]:data-highlighted:bg-foreground/10 **:data-[slot$=-separator]:bg-foreground/5 **:data-[slot$=-trigger]:aria-expanded:bg-foreground/10! **:data-[variant=destructive]:data-highlighted:bg-foreground/10! **:data-[variant=destructive]:text-accent-foreground! **:data-[variant=destructive]:**:text-accent-foreground!", className), ...props }) }) }));
|
|
16
|
-
}
|
|
17
|
-
function DropdownMenuGroup({ ...props }) {
|
|
18
|
-
return _jsx(MenuPrimitive.Group, { "data-slot": "dropdown-menu-group", ...props });
|
|
19
|
-
}
|
|
20
|
-
function DropdownMenuLabel({ className, inset, ...props }) {
|
|
21
|
-
return (_jsx(MenuPrimitive.GroupLabel, { "data-slot": "dropdown-menu-label", "data-inset": inset, className: cn("px-2 py-1.5 text-xs font-medium text-muted-foreground data-inset:pl-8", className), ...props }));
|
|
22
|
-
}
|
|
23
|
-
function DropdownMenuItem({ className, inset, variant = "default", ...props }) {
|
|
24
|
-
return (_jsx(MenuPrimitive.Item, { "data-slot": "dropdown-menu-item", "data-inset": inset, "data-variant": variant, className: cn("group/dropdown-menu-item relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 data-highlighted:bg-accent data-highlighted:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:data-highlighted:bg-destructive/10 data-[variant=destructive]:data-highlighted:text-destructive dark:data-[variant=destructive]:data-highlighted:bg-destructive/20 data-[variant=destructive]:*:[svg]:text-destructive not-data-[variant=destructive]:data-highlighted:**:text-accent-foreground data-inset:pl-8 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0", className), ...props }));
|
|
25
|
-
}
|
|
26
|
-
function DropdownMenuSub({ ...props }) {
|
|
27
|
-
return _jsx(MenuPrimitive.SubmenuRoot, { "data-slot": "dropdown-menu-sub", ...props });
|
|
28
|
-
}
|
|
29
|
-
function DropdownMenuSubTrigger({ className, inset, children, ...props }) {
|
|
30
|
-
return (_jsxs(MenuPrimitive.SubmenuTrigger, { "data-slot": "dropdown-menu-sub-trigger", "data-inset": inset, className: cn("flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-popup-open:bg-accent data-popup-open:text-accent-foreground data-highlighted:bg-accent data-highlighted:text-accent-foreground data-open:bg-accent data-open:text-accent-foreground not-data-[variant=destructive]:data-highlighted:**:text-accent-foreground data-inset:pl-8 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0", className), ...props, children: [children, _jsx(ChevronRightIcon, { className: "ml-auto rtl:-scale-x-100" })] }));
|
|
31
|
-
}
|
|
32
|
-
function DropdownMenuSubContent({ align = "start", alignOffset = -3, side = "right", sideOffset = 0, className, ...props }) {
|
|
33
|
-
return (_jsx(DropdownMenuContent, { "data-slot": "dropdown-menu-sub-content", className: cn("w-auto min-w-[96px] shadow-lg", className), align: align, alignOffset: alignOffset, side: side, sideOffset: sideOffset, ...props }));
|
|
34
|
-
}
|
|
35
|
-
function DropdownMenuCheckboxItem({ className, children, checked, inset, ...props }) {
|
|
36
|
-
return (_jsxs(MenuPrimitive.CheckboxItem, { "data-slot": "dropdown-menu-checkbox-item", "data-inset": inset, className: cn("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 data-highlighted:bg-accent data-highlighted:text-accent-foreground data-highlighted:**:text-accent-foreground data-inset:pl-8 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0", className), checked: checked, ...props, children: [_jsx("span", { className: "pointer-events-none absolute right-2 flex items-center justify-center", "data-slot": "dropdown-menu-checkbox-item-indicator", children: _jsx(MenuPrimitive.CheckboxItemIndicator, { children: _jsx(CheckIcon, {}) }) }), children] }));
|
|
37
|
-
}
|
|
38
|
-
function DropdownMenuRadioGroup({ ...props }) {
|
|
39
|
-
return (_jsx(MenuPrimitive.RadioGroup, { "data-slot": "dropdown-menu-radio-group", ...props }));
|
|
40
|
-
}
|
|
41
|
-
function DropdownMenuRadioItem({ className, children, inset, ...props }) {
|
|
42
|
-
return (_jsxs(MenuPrimitive.RadioItem, { "data-slot": "dropdown-menu-radio-item", "data-inset": inset, className: cn("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 data-highlighted:bg-accent data-highlighted:text-accent-foreground data-highlighted:**:text-accent-foreground data-inset:pl-8 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0", className), ...props, children: [_jsx("span", { className: "pointer-events-none absolute right-2 flex items-center justify-center", "data-slot": "dropdown-menu-radio-item-indicator", children: _jsx(MenuPrimitive.RadioItemIndicator, { children: _jsx(CheckIcon, {}) }) }), children] }));
|
|
43
|
-
}
|
|
44
|
-
function DropdownMenuSeparator({ className, ...props }) {
|
|
45
|
-
return (_jsx(MenuPrimitive.Separator, { "data-slot": "dropdown-menu-separator", className: cn("-mx-1 my-1 h-px bg-border", className), ...props }));
|
|
46
|
-
}
|
|
47
|
-
function DropdownMenuShortcut({ className, ...props }) {
|
|
48
|
-
return (_jsx("span", { "data-slot": "dropdown-menu-shortcut", className: cn("ml-auto text-xs tracking-widest text-muted-foreground group-data-highlighted/dropdown-menu-item:text-accent-foreground", className), ...props }));
|
|
49
|
-
}
|
|
50
|
-
export { DropdownMenu, DropdownMenuPortal, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuItem, DropdownMenuCheckboxItem, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubTrigger, DropdownMenuSubContent, };
|
package/dist/hooks/useApi.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ApiError } from '@ploykit/client';
|
|
2
|
-
export { ApiError };
|
|
3
|
-
export type { ApiFetchOptions } from '@ploykit/client';
|
|
4
|
-
export declare function useApi(): {
|
|
5
|
-
get: <T>(path: string) => Promise<T>;
|
|
6
|
-
post: <T>(path: string, body?: unknown) => Promise<T>;
|
|
7
|
-
put: <T>(path: string, body?: unknown) => Promise<T>;
|
|
8
|
-
patch: <T>(path: string, body?: unknown) => Promise<T>;
|
|
9
|
-
delete: <T>(path: string, body?: unknown) => Promise<T>;
|
|
10
|
-
};
|
package/dist/hooks/useApi.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo } from 'react';
|
|
2
|
-
import { api, ApiError } from '@ploykit/client';
|
|
3
|
-
export { ApiError };
|
|
4
|
-
export function useApi() {
|
|
5
|
-
const get = useCallback((path) => api.get(path), []);
|
|
6
|
-
const post = useCallback((path, body) => api.post(path, body), []);
|
|
7
|
-
const put = useCallback((path, body) => api.put(path, body), []);
|
|
8
|
-
const patch = useCallback((path, body) => api.patch(path, body), []);
|
|
9
|
-
const del = useCallback((path, body) => api.delete(path, body), []);
|
|
10
|
-
return useMemo(() => ({ get, post, put, patch, delete: del }), [get, post, put, patch, del]);
|
|
11
|
-
}
|
package/dist/hooks/useAudit.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { components } from '@ploykit/client';
|
|
2
|
-
export type PKAuditEvent = components['schemas']['AuditEvent'];
|
|
3
|
-
export interface AuditListResp {
|
|
4
|
-
items: PKAuditEvent[];
|
|
5
|
-
total: number;
|
|
6
|
-
}
|
|
7
|
-
export interface AuditFilters {
|
|
8
|
-
action: string;
|
|
9
|
-
actorId: string;
|
|
10
|
-
resourceType: string;
|
|
11
|
-
from: string;
|
|
12
|
-
to: string;
|
|
13
|
-
}
|
|
14
|
-
export declare const EMPTY_AUDIT_FILTERS: AuditFilters;
|
|
15
|
-
export declare function auditQueryString(f: AuditFilters, limit: number, offset: number): string;
|
|
16
|
-
export declare function useAudit(filters: AuditFilters, limit?: number, offset?: number): {
|
|
17
|
-
wsId: string;
|
|
18
|
-
items: {
|
|
19
|
-
id: string;
|
|
20
|
-
workspace_id: string;
|
|
21
|
-
actor_type: "user" | "pat" | "system";
|
|
22
|
-
actor_id: string | null;
|
|
23
|
-
actor_snapshot: {
|
|
24
|
-
[key: string]: unknown;
|
|
25
|
-
};
|
|
26
|
-
action: string;
|
|
27
|
-
resource_type: string;
|
|
28
|
-
resource_id: string | null;
|
|
29
|
-
metadata: {
|
|
30
|
-
[key: string]: unknown;
|
|
31
|
-
};
|
|
32
|
-
created_at: string;
|
|
33
|
-
}[];
|
|
34
|
-
total: number;
|
|
35
|
-
loading: boolean;
|
|
36
|
-
error: Error | null;
|
|
37
|
-
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<AuditListResp, Error>>;
|
|
38
|
-
};
|
|
39
|
-
export declare function exportAuditCsv(filters: AuditFilters): Promise<void>;
|
package/dist/hooks/useAudit.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { useQuery } from '@tanstack/react-query';
|
|
2
|
-
import { apiFetch } from '@ploykit/client';
|
|
3
|
-
import { useApi } from './useApi';
|
|
4
|
-
import { useWorkspace } from './useWorkspace';
|
|
5
|
-
import { queryKeys } from '../provider/PloykitProvider';
|
|
6
|
-
export const EMPTY_AUDIT_FILTERS = {
|
|
7
|
-
action: '', actorId: '', resourceType: '', from: '', to: '',
|
|
8
|
-
};
|
|
9
|
-
export function auditQueryString(f, limit, offset) {
|
|
10
|
-
const q = new URLSearchParams();
|
|
11
|
-
if (f.action)
|
|
12
|
-
q.set('action', f.action);
|
|
13
|
-
if (f.actorId)
|
|
14
|
-
q.set('actor_id', f.actorId);
|
|
15
|
-
if (f.resourceType)
|
|
16
|
-
q.set('resource_type', f.resourceType);
|
|
17
|
-
if (f.from)
|
|
18
|
-
q.set('from', f.from);
|
|
19
|
-
if (f.to)
|
|
20
|
-
q.set('to', f.to);
|
|
21
|
-
q.set('limit', String(limit));
|
|
22
|
-
q.set('offset', String(offset));
|
|
23
|
-
return q.toString();
|
|
24
|
-
}
|
|
25
|
-
export function useAudit(filters, limit = 20, offset = 0) {
|
|
26
|
-
const { current } = useWorkspace();
|
|
27
|
-
const api = useApi();
|
|
28
|
-
const wsId = current?.id ?? '';
|
|
29
|
-
const qs = auditQueryString(filters, limit, offset);
|
|
30
|
-
const q = useQuery({
|
|
31
|
-
queryKey: queryKeys.audit(wsId, { ...filters, limit, offset }),
|
|
32
|
-
queryFn: () => api.get(`/api/audit?${qs}`),
|
|
33
|
-
enabled: !!wsId,
|
|
34
|
-
});
|
|
35
|
-
return {
|
|
36
|
-
wsId,
|
|
37
|
-
items: wsId ? (q.data?.items ?? []) : [],
|
|
38
|
-
total: wsId ? (q.data?.total ?? 0) : 0,
|
|
39
|
-
loading: !!wsId && q.isPending,
|
|
40
|
-
error: q.error,
|
|
41
|
-
refetch: q.refetch,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
export async function exportAuditCsv(filters) {
|
|
45
|
-
const qs = auditQueryString(filters, 5000, 0);
|
|
46
|
-
const blob = await apiFetch(`/api/audit/export.csv?${qs}`, { responseType: 'blob' });
|
|
47
|
-
const url = URL.createObjectURL(blob);
|
|
48
|
-
const a = document.createElement('a');
|
|
49
|
-
a.href = url;
|
|
50
|
-
a.download = `audit-${new Date().toISOString().slice(0, 10)}.csv`;
|
|
51
|
-
document.body.appendChild(a);
|
|
52
|
-
a.click();
|
|
53
|
-
a.remove();
|
|
54
|
-
URL.revokeObjectURL(url);
|
|
55
|
-
}
|
package/dist/hooks/useAuth.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useAuth(): import("../provider/PloykitProvider").AuthContextValue;
|
package/dist/hooks/useAuth.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { type ReactNode } from 'react';
|
|
2
|
-
import { type components } from '@ploykit/client';
|
|
3
|
-
export declare function useBilling(): {
|
|
4
|
-
subscription: {
|
|
5
|
-
plan_code: string;
|
|
6
|
-
orders: components["schemas"]["Order"][];
|
|
7
|
-
} | null;
|
|
8
|
-
plans: {
|
|
9
|
-
code: string;
|
|
10
|
-
name: string;
|
|
11
|
-
currency?: string;
|
|
12
|
-
trial_days?: number;
|
|
13
|
-
limits: {
|
|
14
|
-
[key: string]: number;
|
|
15
|
-
};
|
|
16
|
-
sort_no: number;
|
|
17
|
-
}[];
|
|
18
|
-
checkout: (planCode: string, interval: string, channel: string) => Promise<{
|
|
19
|
-
order_id: string;
|
|
20
|
-
channel: "stripe" | "alipay" | "wechat";
|
|
21
|
-
action_url: string;
|
|
22
|
-
session_ref: string;
|
|
23
|
-
expires_at: string;
|
|
24
|
-
} | null>;
|
|
25
|
-
checkoutError: Error | null;
|
|
26
|
-
loading: boolean;
|
|
27
|
-
refresh: () => Promise<void>;
|
|
28
|
-
};
|
|
29
|
-
export declare function PlanGate({ plan, denied, children, busy }: {
|
|
30
|
-
plan: string;
|
|
31
|
-
denied?: ReactNode;
|
|
32
|
-
children: ReactNode;
|
|
33
|
-
busy?: ReactNode;
|
|
34
|
-
}): import("react").JSX.Element;
|
|
35
|
-
export type UsagePreviewItem = components['schemas']['UsagePreviewItem'];
|
|
36
|
-
export type UsagePreviewResp = components['schemas']['UsagePreview'];
|
|
37
|
-
export declare function useUsagePreview(): {
|
|
38
|
-
preview: {
|
|
39
|
-
period: string;
|
|
40
|
-
items: components["schemas"]["UsagePreviewItem"][];
|
|
41
|
-
projected_total_cents: number;
|
|
42
|
-
} | null;
|
|
43
|
-
loading: boolean;
|
|
44
|
-
};
|
package/dist/hooks/useBilling.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback } from 'react';
|
|
3
|
-
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
4
|
-
import { api } from '@ploykit/client';
|
|
5
|
-
import { useWorkspaceCtx, queryKeys, } from '../provider/PloykitProvider';
|
|
6
|
-
export function useBilling() {
|
|
7
|
-
const { current } = useWorkspaceCtx();
|
|
8
|
-
const qc = useQueryClient();
|
|
9
|
-
const wsId = current?.id ?? '';
|
|
10
|
-
const subQ = useQuery({
|
|
11
|
-
queryKey: queryKeys.billingSubscription(wsId),
|
|
12
|
-
queryFn: () => api.get('/api/billing/subscription'),
|
|
13
|
-
enabled: !!current,
|
|
14
|
-
});
|
|
15
|
-
const planQ = useQuery({
|
|
16
|
-
queryKey: queryKeys.billingPlans,
|
|
17
|
-
queryFn: () => api.get('/api/billing/plans'),
|
|
18
|
-
});
|
|
19
|
-
const checkoutM = useMutation({
|
|
20
|
-
mutationFn: (v) => api.post('/api/billing/checkout', {
|
|
21
|
-
plan_code: v.planCode, interval: v.interval, channel: v.channel,
|
|
22
|
-
}),
|
|
23
|
-
onSuccess: () => qc.invalidateQueries({ queryKey: queryKeys.billing }),
|
|
24
|
-
});
|
|
25
|
-
const checkout = useCallback(async (planCode, interval, channel) => {
|
|
26
|
-
if (!wsId)
|
|
27
|
-
return null;
|
|
28
|
-
return checkoutM.mutateAsync({ planCode, interval, channel }).catch(() => null);
|
|
29
|
-
}, [wsId, checkoutM.mutateAsync]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
30
|
-
const refresh = useCallback(async () => {
|
|
31
|
-
await qc.invalidateQueries({ queryKey: queryKeys.billing });
|
|
32
|
-
}, [qc]);
|
|
33
|
-
return {
|
|
34
|
-
subscription: current ? (subQ.data ?? null) : null,
|
|
35
|
-
plans: Array.isArray(planQ.data) ? planQ.data : [],
|
|
36
|
-
checkout,
|
|
37
|
-
checkoutError: checkoutM.error ?? null,
|
|
38
|
-
loading: planQ.isPending || (!!current && subQ.isPending),
|
|
39
|
-
refresh,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
export function PlanGate({ plan, denied, children, busy }) {
|
|
43
|
-
const { subscription, plans, loading } = useBilling();
|
|
44
|
-
if (loading)
|
|
45
|
-
return _jsx(_Fragment, { children: busy ?? null });
|
|
46
|
-
if (!subscription)
|
|
47
|
-
return _jsx(_Fragment, { children: denied ?? null });
|
|
48
|
-
const currentPlan = plans.find((p) => p.code === subscription.plan_code);
|
|
49
|
-
const requiredPlan = plans.find((p) => p.code === plan);
|
|
50
|
-
const entitled = currentPlan && requiredPlan && currentPlan.sort_no >= requiredPlan.sort_no;
|
|
51
|
-
return _jsx(_Fragment, { children: entitled ? children : denied });
|
|
52
|
-
}
|
|
53
|
-
export function useUsagePreview() {
|
|
54
|
-
const { current } = useWorkspaceCtx();
|
|
55
|
-
const previewQ = useQuery({
|
|
56
|
-
queryKey: ['billing', 'usage-preview', current?.id ?? ''],
|
|
57
|
-
queryFn: () => api.get('/api/billing/usage-preview'),
|
|
58
|
-
enabled: !!current,
|
|
59
|
-
});
|
|
60
|
-
return {
|
|
61
|
-
preview: current ? (previewQ.data ?? null) : null,
|
|
62
|
-
loading: !!current && previewQ.isPending,
|
|
63
|
-
};
|
|
64
|
-
}
|
package/dist/hooks/useLogin.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export interface UseLoginResult {
|
|
2
|
-
sendCode(email: string): Promise<void>;
|
|
3
|
-
submit(email: string, code: string): Promise<{
|
|
4
|
-
ok: boolean;
|
|
5
|
-
error?: string;
|
|
6
|
-
}>;
|
|
7
|
-
loading: boolean;
|
|
8
|
-
error: string | null;
|
|
9
|
-
}
|
|
10
|
-
export declare function useLogin(): UseLoginResult;
|
package/dist/hooks/useLogin.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { useCallback, useState } from 'react';
|
|
2
|
-
import { api } from '@ploykit/client';
|
|
3
|
-
import { useAuthCtx } from '../provider/PloykitProvider';
|
|
4
|
-
export function useLogin() {
|
|
5
|
-
const [loading, setLoading] = useState(false);
|
|
6
|
-
const [error, setError] = useState(null);
|
|
7
|
-
const { refresh } = useAuthCtx();
|
|
8
|
-
const sendCode = useCallback(async (email) => {
|
|
9
|
-
setError(null);
|
|
10
|
-
setLoading(true);
|
|
11
|
-
try {
|
|
12
|
-
await api.post('/auth/send-code', { email });
|
|
13
|
-
}
|
|
14
|
-
catch (e) {
|
|
15
|
-
setError(e instanceof Error ? e.message : '发送失败');
|
|
16
|
-
}
|
|
17
|
-
finally {
|
|
18
|
-
setLoading(false);
|
|
19
|
-
}
|
|
20
|
-
}, []);
|
|
21
|
-
const submit = useCallback(async (email, code) => {
|
|
22
|
-
setError(null);
|
|
23
|
-
setLoading(true);
|
|
24
|
-
try {
|
|
25
|
-
await api.post('/auth/verify-code', { email, code });
|
|
26
|
-
await refresh();
|
|
27
|
-
return { ok: true };
|
|
28
|
-
}
|
|
29
|
-
catch (e) {
|
|
30
|
-
const msg = e instanceof Error ? e.message : '登录失败';
|
|
31
|
-
setError(msg);
|
|
32
|
-
return { ok: false, error: msg };
|
|
33
|
-
}
|
|
34
|
-
finally {
|
|
35
|
-
setLoading(false);
|
|
36
|
-
}
|
|
37
|
-
}, [refresh]);
|
|
38
|
-
return { sendCode, submit, loading, error };
|
|
39
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import type { components } from '@ploykit/client';
|
|
2
|
-
export type PKMember = components['schemas']['Member'];
|
|
3
|
-
export type PKInvitation = components['schemas']['Invitation'];
|
|
4
|
-
export type PKShareLink = components['schemas']['ShareLink'];
|
|
5
|
-
export type PKInvitationWithWorkspace = components['schemas']['InvitationWithWorkspace'];
|
|
6
|
-
export type PKMemberPage = components['schemas']['MemberPage'];
|
|
7
|
-
export type PKInvitationPage = components['schemas']['InvitationPage'];
|
|
8
|
-
export type PKShareLinkPage = components['schemas']['ShareLinkPage'];
|
|
9
|
-
export interface ListQuery {
|
|
10
|
-
page: number;
|
|
11
|
-
pageSize?: number;
|
|
12
|
-
}
|
|
13
|
-
export interface ListPages {
|
|
14
|
-
members: number;
|
|
15
|
-
invitations: number;
|
|
16
|
-
shareLinks: number;
|
|
17
|
-
}
|
|
18
|
-
export declare const LIST_PAGE_SIZE = 50;
|
|
19
|
-
export interface CreateShareLinkResult {
|
|
20
|
-
link: PKShareLink;
|
|
21
|
-
code: string;
|
|
22
|
-
}
|
|
23
|
-
export declare const ASSIGNABLE_ROLES: readonly ["admin", "member"];
|
|
24
|
-
export declare function useMembers(pages: ListPages): {
|
|
25
|
-
wsId: string;
|
|
26
|
-
myRole: "owner" | "admin" | "member" | null;
|
|
27
|
-
members: {
|
|
28
|
-
user_id: string;
|
|
29
|
-
email: string;
|
|
30
|
-
display_name: string;
|
|
31
|
-
role: "owner" | "admin" | "member";
|
|
32
|
-
created_at: string;
|
|
33
|
-
}[];
|
|
34
|
-
membersTotal: number;
|
|
35
|
-
invitations: {
|
|
36
|
-
id: string;
|
|
37
|
-
workspace_id: string;
|
|
38
|
-
email: string;
|
|
39
|
-
role: "owner" | "admin" | "member";
|
|
40
|
-
status: "pending" | "accepted" | "declined" | "revoked" | "expired";
|
|
41
|
-
expires_at: string;
|
|
42
|
-
created_at: string;
|
|
43
|
-
}[];
|
|
44
|
-
invitationsTotal: number;
|
|
45
|
-
shareLinks: {
|
|
46
|
-
id: string;
|
|
47
|
-
code_prefix: string;
|
|
48
|
-
role: "admin" | "member";
|
|
49
|
-
max_uses: number;
|
|
50
|
-
uses: number;
|
|
51
|
-
expires_at: string;
|
|
52
|
-
created_at: string;
|
|
53
|
-
}[];
|
|
54
|
-
shareLinksTotal: number;
|
|
55
|
-
loading: boolean;
|
|
56
|
-
membersError: Error | null;
|
|
57
|
-
invitationsError: Error | null;
|
|
58
|
-
shareLinksError: Error | null;
|
|
59
|
-
refetchAll: () => Promise<void>;
|
|
60
|
-
};
|
|
61
|
-
export declare function useMemberMutations(): {
|
|
62
|
-
invite: import("@tanstack/react-query").UseMutationResult<{
|
|
63
|
-
id: string;
|
|
64
|
-
workspace_id: string;
|
|
65
|
-
email: string;
|
|
66
|
-
role: "owner" | "admin" | "member";
|
|
67
|
-
status: "pending" | "accepted" | "declined" | "revoked" | "expired";
|
|
68
|
-
expires_at: string;
|
|
69
|
-
created_at: string;
|
|
70
|
-
}, Error, {
|
|
71
|
-
email: string;
|
|
72
|
-
role: string;
|
|
73
|
-
}, unknown>;
|
|
74
|
-
revokeInvitation: import("@tanstack/react-query").UseMutationResult<unknown, Error, string, unknown>;
|
|
75
|
-
updateRole: import("@tanstack/react-query").UseMutationResult<unknown, Error, {
|
|
76
|
-
userId: string;
|
|
77
|
-
role: string;
|
|
78
|
-
}, unknown>;
|
|
79
|
-
removeMember: import("@tanstack/react-query").UseMutationResult<unknown, Error, string, unknown>;
|
|
80
|
-
transferOwnership: import("@tanstack/react-query").UseMutationResult<unknown, Error, string, unknown>;
|
|
81
|
-
createShareLink: import("@tanstack/react-query").UseMutationResult<CreateShareLinkResult, Error, {
|
|
82
|
-
role: string;
|
|
83
|
-
max_uses: number;
|
|
84
|
-
ttl_hours: number;
|
|
85
|
-
}, unknown>;
|
|
86
|
-
revokeShareLink: import("@tanstack/react-query").UseMutationResult<unknown, Error, string, unknown>;
|
|
87
|
-
};
|
|
88
|
-
export declare function useMyInvitations(): {
|
|
89
|
-
invitations: ({
|
|
90
|
-
id: string;
|
|
91
|
-
workspace_id: string;
|
|
92
|
-
email: string;
|
|
93
|
-
role: "owner" | "admin" | "member";
|
|
94
|
-
status: "pending" | "accepted" | "declined" | "revoked" | "expired";
|
|
95
|
-
expires_at: string;
|
|
96
|
-
created_at: string;
|
|
97
|
-
} & {
|
|
98
|
-
workspace_name: string;
|
|
99
|
-
workspace_slug: string;
|
|
100
|
-
})[];
|
|
101
|
-
loading: boolean;
|
|
102
|
-
error: Error | null;
|
|
103
|
-
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<({
|
|
104
|
-
id: string;
|
|
105
|
-
workspace_id: string;
|
|
106
|
-
email: string;
|
|
107
|
-
role: "owner" | "admin" | "member";
|
|
108
|
-
status: "pending" | "accepted" | "declined" | "revoked" | "expired";
|
|
109
|
-
expires_at: string;
|
|
110
|
-
created_at: string;
|
|
111
|
-
} & {
|
|
112
|
-
workspace_name: string;
|
|
113
|
-
workspace_slug: string;
|
|
114
|
-
})[], Error>>;
|
|
115
|
-
accept: import("@tanstack/react-query").UseMutationResult<{
|
|
116
|
-
id: string;
|
|
117
|
-
slug: string;
|
|
118
|
-
name: string;
|
|
119
|
-
plan_code: string;
|
|
120
|
-
created_at: string;
|
|
121
|
-
} & {
|
|
122
|
-
role: "owner" | "admin" | "member";
|
|
123
|
-
}, Error, string, unknown>;
|
|
124
|
-
decline: import("@tanstack/react-query").UseMutationResult<unknown, Error, string, unknown>;
|
|
125
|
-
};
|
package/dist/hooks/useMembers.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
2
|
-
import { useApi } from './useApi';
|
|
3
|
-
import { useWorkspace } from './useWorkspace';
|
|
4
|
-
import { queryKeys } from '../provider/PloykitProvider';
|
|
5
|
-
export const LIST_PAGE_SIZE = 50;
|
|
6
|
-
const listQuery = (q) => `?page=${q.page}&page_size=${q.pageSize ?? LIST_PAGE_SIZE}`;
|
|
7
|
-
export const ASSIGNABLE_ROLES = ['admin', 'member'];
|
|
8
|
-
export function useMembers(pages) {
|
|
9
|
-
const { current } = useWorkspace();
|
|
10
|
-
const api = useApi();
|
|
11
|
-
const wsId = current?.id ?? '';
|
|
12
|
-
const membersQ = useQuery({
|
|
13
|
-
queryKey: [...queryKeys.members(wsId), pages.members],
|
|
14
|
-
queryFn: () => api.get(`/api/workspaces/${wsId}/members${listQuery({ page: pages.members })}`),
|
|
15
|
-
enabled: !!wsId,
|
|
16
|
-
});
|
|
17
|
-
const invitationsQ = useQuery({
|
|
18
|
-
queryKey: [...queryKeys.invitations(wsId), pages.invitations],
|
|
19
|
-
queryFn: () => api.get(`/api/workspaces/${wsId}/invitations${listQuery({ page: pages.invitations })}`),
|
|
20
|
-
enabled: !!wsId,
|
|
21
|
-
});
|
|
22
|
-
const shareLinksQ = useQuery({
|
|
23
|
-
queryKey: [...queryKeys.shareLinks(wsId), pages.shareLinks],
|
|
24
|
-
queryFn: () => api.get(`/api/workspaces/${wsId}/share-links${listQuery({ page: pages.shareLinks })}`),
|
|
25
|
-
enabled: !!wsId,
|
|
26
|
-
});
|
|
27
|
-
return {
|
|
28
|
-
wsId,
|
|
29
|
-
myRole: current?.role ?? null,
|
|
30
|
-
members: membersQ.data?.items ?? [],
|
|
31
|
-
membersTotal: membersQ.data?.total ?? 0,
|
|
32
|
-
invitations: invitationsQ.data?.items ?? [],
|
|
33
|
-
invitationsTotal: invitationsQ.data?.total ?? 0,
|
|
34
|
-
shareLinks: shareLinksQ.data?.items ?? [],
|
|
35
|
-
shareLinksTotal: shareLinksQ.data?.total ?? 0,
|
|
36
|
-
loading: !!wsId && (membersQ.isPending || invitationsQ.isPending || shareLinksQ.isPending),
|
|
37
|
-
membersError: membersQ.error,
|
|
38
|
-
invitationsError: invitationsQ.error,
|
|
39
|
-
shareLinksError: shareLinksQ.error,
|
|
40
|
-
refetchAll: async () => {
|
|
41
|
-
await Promise.all([
|
|
42
|
-
membersQ.refetch(),
|
|
43
|
-
invitationsQ.refetch(),
|
|
44
|
-
shareLinksQ.refetch(),
|
|
45
|
-
]);
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
export function useMemberMutations() {
|
|
50
|
-
const { current } = useWorkspace();
|
|
51
|
-
const api = useApi();
|
|
52
|
-
const qc = useQueryClient();
|
|
53
|
-
const wsId = current?.id ?? '';
|
|
54
|
-
const base = `/api/workspaces/${wsId}`;
|
|
55
|
-
const invalidateAll = async () => {
|
|
56
|
-
await Promise.all([
|
|
57
|
-
qc.invalidateQueries({ queryKey: queryKeys.members(wsId) }),
|
|
58
|
-
qc.invalidateQueries({ queryKey: queryKeys.invitations(wsId) }),
|
|
59
|
-
qc.invalidateQueries({ queryKey: queryKeys.shareLinks(wsId) }),
|
|
60
|
-
]);
|
|
61
|
-
};
|
|
62
|
-
const invite = useMutation({
|
|
63
|
-
mutationFn: (v) => api.post(`${base}/invitations`, v),
|
|
64
|
-
onSuccess: invalidateAll,
|
|
65
|
-
});
|
|
66
|
-
const revokeInvitation = useMutation({
|
|
67
|
-
mutationFn: (invId) => api.delete(`${base}/invitations/${invId}`),
|
|
68
|
-
onSuccess: invalidateAll,
|
|
69
|
-
});
|
|
70
|
-
const updateRole = useMutation({
|
|
71
|
-
mutationFn: (v) => api.patch(`${base}/members/${v.userId}`, { role: v.role }),
|
|
72
|
-
onSuccess: invalidateAll,
|
|
73
|
-
});
|
|
74
|
-
const removeMember = useMutation({
|
|
75
|
-
mutationFn: (userId) => api.delete(`${base}/members/${userId}`),
|
|
76
|
-
onSuccess: invalidateAll,
|
|
77
|
-
});
|
|
78
|
-
const transferOwnership = useMutation({
|
|
79
|
-
mutationFn: (userId) => api.post(`${base}/transfer-ownership`, { user_id: userId }),
|
|
80
|
-
onSuccess: async () => {
|
|
81
|
-
await invalidateAll();
|
|
82
|
-
await qc.invalidateQueries({ queryKey: queryKeys.workspace });
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
const createShareLink = useMutation({
|
|
86
|
-
mutationFn: (v) => api.post(`${base}/share-links`, v),
|
|
87
|
-
onSuccess: invalidateAll,
|
|
88
|
-
});
|
|
89
|
-
const revokeShareLink = useMutation({
|
|
90
|
-
mutationFn: (linkId) => api.delete(`${base}/share-links/${linkId}`),
|
|
91
|
-
onSuccess: invalidateAll,
|
|
92
|
-
});
|
|
93
|
-
return {
|
|
94
|
-
invite, revokeInvitation, updateRole, removeMember, transferOwnership,
|
|
95
|
-
createShareLink, revokeShareLink,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
export function useMyInvitations() {
|
|
99
|
-
const api = useApi();
|
|
100
|
-
const qc = useQueryClient();
|
|
101
|
-
const list = useQuery({
|
|
102
|
-
queryKey: queryKeys.myInvitations,
|
|
103
|
-
queryFn: () => api.get('/api/invitations/mine'),
|
|
104
|
-
});
|
|
105
|
-
const invalidate = () => qc.invalidateQueries({ queryKey: queryKeys.myInvitations });
|
|
106
|
-
const accept = useMutation({
|
|
107
|
-
mutationFn: (id) => api.post(`/api/invitations/${id}/accept`),
|
|
108
|
-
onSuccess: async () => {
|
|
109
|
-
await Promise.all([
|
|
110
|
-
invalidate(),
|
|
111
|
-
qc.invalidateQueries({ queryKey: queryKeys.workspace }),
|
|
112
|
-
]);
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
const decline = useMutation({
|
|
116
|
-
mutationFn: (id) => api.post(`/api/invitations/${id}/decline`),
|
|
117
|
-
onSuccess: invalidate,
|
|
118
|
-
});
|
|
119
|
-
return {
|
|
120
|
-
invitations: list.data ?? [],
|
|
121
|
-
loading: list.isPending,
|
|
122
|
-
error: list.error,
|
|
123
|
-
refetch: list.refetch,
|
|
124
|
-
accept,
|
|
125
|
-
decline,
|
|
126
|
-
};
|
|
127
|
-
}
|