@greatapps/common 1.1.377 → 1.1.379
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/dist/components/layouts/ProfilePopover.mjs +4 -8
- package/dist/components/layouts/ProfilePopover.mjs.map +1 -1
- package/dist/infra/api/types.mjs +1 -1
- package/dist/infra/api/types.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/layouts/ProfilePopover.tsx +4 -8
- package/src/infra/api/types.ts +4 -4
|
@@ -29,13 +29,9 @@ function ProfilePopover({
|
|
|
29
29
|
const { accountsUrl } = useWhitelabelUrls();
|
|
30
30
|
const router = useRouter();
|
|
31
31
|
const handleLogout = async () => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
await logout();
|
|
36
|
-
} finally {
|
|
37
|
-
setIsLoggingOut(false);
|
|
38
|
-
}
|
|
32
|
+
setPopoverOpen(false);
|
|
33
|
+
setIsLoggingOut(true);
|
|
34
|
+
await logout();
|
|
39
35
|
};
|
|
40
36
|
const hasSubscription = !isSubscriptionLoading && subscription !== null;
|
|
41
37
|
const shouldShowCredits = hasSubscription && subscription.id_wl === 1;
|
|
@@ -92,7 +88,7 @@ function ProfilePopover({
|
|
|
92
88
|
const isSameOrigin = accountsUrl.startsWith(window.location.origin);
|
|
93
89
|
if (isSameOrigin) {
|
|
94
90
|
setPopoverOpen(false);
|
|
95
|
-
router.push(`${
|
|
91
|
+
router.push(`${window.location.pathname}?openProfile=true`);
|
|
96
92
|
} else {
|
|
97
93
|
window.location.href = `${accountsUrl}?openProfile=true`;
|
|
98
94
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/layouts/ProfilePopover.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState } from \"react\";\nimport { useRouter } from \"next/navigation\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport { Popover } from \"../ui/overlay/Popover\";\nimport { Button } from \"../ui/buttons/Button\";\nimport { Progress } from \"../ui/feedback/Progress\";\nimport { Separator } from \"../ui/data-display/Separator\";\nimport { NavBarItem } from \"./NavBarItem\";\nimport { UserAvatar } from \"../ui/data-display/UserAvatar\";\nimport { LoadingOverlay } from \"../ui/feedback/LoadingOverlay\";\nimport { useAuth } from \"../../providers/auth.provider\";\nimport { useWhitelabelUrls } from \"../../providers/whitelabel.provider\";\nimport { cn } from \"../../infra/utils/clsx\";\nimport { useIaCredits } from \"../../modules/ia-credits/hooks/ia-credits.hook\";\nimport { useBuyCreditsModal } from \"../../store/useBuyCreditsModal\";\n\nexport interface ProfileMenuItem {\n icon?: React.ReactNode;\n label: string;\n onClick: () => void;\n}\n\nexport interface ProfilePopoverProps {\n side?: \"top\" | \"bottom\" | \"left\" | \"right\";\n align?: \"start\" | \"center\" | \"end\";\n contentClassName?: string;\n menuItems?: ProfileMenuItem[];\n}\n\nfunction ProfilePopover({\n side = \"top\",\n align = \"start\",\n contentClassName = \"absolute bottom-2 left-[26px]\",\n menuItems = [],\n}: ProfilePopoverProps) {\n const { user, logout } = useAuth();\n const [isLoggingOut, setIsLoggingOut] = useState(false);\n const [popoverOpen, setPopoverOpen] = useState(false);\n\n const { summary, subscription, isSubscriptionLoading, isCreditsLoading } =\n useIaCredits();\n const { openModal: openBuyCreditsModal } = useBuyCreditsModal();\n const { accountsUrl } = useWhitelabelUrls();\n const router = useRouter();\n\n const handleLogout = async () => {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/components/layouts/ProfilePopover.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState } from \"react\";\nimport { useRouter } from \"next/navigation\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport { Popover } from \"../ui/overlay/Popover\";\nimport { Button } from \"../ui/buttons/Button\";\nimport { Progress } from \"../ui/feedback/Progress\";\nimport { Separator } from \"../ui/data-display/Separator\";\nimport { NavBarItem } from \"./NavBarItem\";\nimport { UserAvatar } from \"../ui/data-display/UserAvatar\";\nimport { LoadingOverlay } from \"../ui/feedback/LoadingOverlay\";\nimport { useAuth } from \"../../providers/auth.provider\";\nimport { useWhitelabelUrls } from \"../../providers/whitelabel.provider\";\nimport { cn } from \"../../infra/utils/clsx\";\nimport { useIaCredits } from \"../../modules/ia-credits/hooks/ia-credits.hook\";\nimport { useBuyCreditsModal } from \"../../store/useBuyCreditsModal\";\n\nexport interface ProfileMenuItem {\n icon?: React.ReactNode;\n label: string;\n onClick: () => void;\n}\n\nexport interface ProfilePopoverProps {\n side?: \"top\" | \"bottom\" | \"left\" | \"right\";\n align?: \"start\" | \"center\" | \"end\";\n contentClassName?: string;\n menuItems?: ProfileMenuItem[];\n}\n\nfunction ProfilePopover({\n side = \"top\",\n align = \"start\",\n contentClassName = \"absolute bottom-2 left-[26px]\",\n menuItems = [],\n}: ProfilePopoverProps) {\n const { user, logout } = useAuth();\n const [isLoggingOut, setIsLoggingOut] = useState(false);\n const [popoverOpen, setPopoverOpen] = useState(false);\n\n const { summary, subscription, isSubscriptionLoading, isCreditsLoading } =\n useIaCredits();\n const { openModal: openBuyCreditsModal } = useBuyCreditsModal();\n const { accountsUrl } = useWhitelabelUrls();\n const router = useRouter();\n\n const handleLogout = async () => {\n setPopoverOpen(false);\n setIsLoggingOut(true);\n await logout();\n };\n\n const hasSubscription = !isSubscriptionLoading && subscription !== null;\n\n const shouldShowCredits = hasSubscription && subscription.id_wl === 1;\n const creditsPercentage =\n shouldShowCredits && summary.totalCredits > 0\n ? (summary.usedCredits / summary.totalCredits) * 100\n : 0;\n\n return (\n <>\n <LoadingOverlay\n isLoading={isLoggingOut}\n message=\"Saindo da sua conta...\"\n />\n <Popover open={popoverOpen} onOpenChange={setPopoverOpen}>\n <PopoverPrimitive.Trigger className=\"cursor-pointer\">\n {user && (\n <UserAvatar\n key={user.id}\n photo={user.photo}\n name={user.name}\n size={40}\n />\n )}\n </PopoverPrimitive.Trigger>\n\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n className={cn(\n \"w-64.75 p-0 bg-white rounded-2xl shadow-md border border-gray-200 z-99\",\n contentClassName,\n )}\n side={side}\n align={align}\n sideOffset={8}\n >\n <div className=\"grid grid-cols-[32px_1fr_auto] items-center gap-3 p-3 w-full\">\n {user && (\n <UserAvatar\n key={user.id}\n photo={user.photo}\n name={user.name}\n size={32}\n />\n )}\n\n <div className=\"flex flex-col gap-0.5 min-w-0\">\n <span className=\"paragraph-small-semibold text-gray-950 truncate\">\n {user?.name || \"\"}\n </span>\n <span className=\"paragraph-xsmall-medium text-gray-500 truncate\">\n {user?.email || \"\"}\n </span>\n </div>\n\n <Button\n variant=\"secondary\"\n className=\"h-8! px-3! paragraph-xsmall-semibold\"\n onClick={() => {\n const isSameOrigin = accountsUrl.startsWith(window.location.origin);\n if (isSameOrigin) {\n setPopoverOpen(false);\n router.push(`${window.location.pathname}?openProfile=true`);\n } else {\n window.location.href = `${accountsUrl}?openProfile=true`;\n }\n }}\n >\n Editar\n </Button>\n </div>\n\n <div className=\"flex flex-col gap-2 border-t border-gray-200 rounded-2xl p-1.5\">\n {shouldShowCredits && (\n <div\n className={cn(\n \"flex flex-col bg-gray-950 rounded-lg gap-4 w-full p-4 transition-colors\",\n \"cursor-pointer hover:bg-gray-950/90\",\n )}\n onClick={() => openBuyCreditsModal()}\n >\n <div className=\"flex items-center justify-between gap-2\">\n <span className=\"paragraph-xsmall-semibold text-white truncate\">\n Créditos usados\n </span>\n <span className=\"paragraph-xsmall-medium text-white/50\">\n {summary.usedCredits.toLocaleString(\"pt-BR\")}/\n {summary.totalCredits.toLocaleString(\"pt-BR\")}\n </span>\n </div>\n <Progress\n className=\"bg-white/10\"\n indicatorColor=\"bg-white\"\n value={creditsPercentage}\n />\n </div>\n )}\n\n <div className=\"flex flex-col gap-2\">\n <div className=\"flex flex-col\">\n {menuItems.map((item, index) => (\n <NavBarItem\n key={index}\n icon={item.icon}\n label={item.label}\n onClick={item.onClick}\n />\n ))}\n </div>\n <Separator />\n <NavBarItem label=\"Sair\" onClick={handleLogout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A,kBAEnC;AAAA,yCAAC,SAAI,WAAU,2CACb;AAAA,0CAAC,UAAK,WAAU,iDAAgD,gCAEhE;AAAA,sBACA,qBAAC,UAAK,WAAU,yCACb;AAAA,gCAAQ,YAAY,eAAe,OAAO;AAAA,wBAAE;AAAA,wBAC5C,QAAQ,aAAa,eAAe,OAAO;AAAA,yBAC9C;AAAA,uBACF;AAAA,oBACA;AAAA,sBAAC;AAAA;AAAA,wBACC,WAAU;AAAA,wBACV,gBAAe;AAAA,wBACf,OAAO;AAAA;AAAA,oBACT;AAAA;AAAA;AAAA,cACF;AAAA,cAGF,qBAAC,SAAI,WAAU,uBACb;AAAA,oCAAC,SAAI,WAAU,iBACZ,oBAAU,IAAI,CAAC,MAAM,UACpB;AAAA,kBAAC;AAAA;AAAA,oBAEC,MAAM,KAAK;AAAA,oBACX,OAAO,KAAK;AAAA,oBACZ,SAAS,KAAK;AAAA;AAAA,kBAHT;AAAA,gBAIP,CACD,GACH;AAAA,gBACA,oBAAC,aAAU;AAAA,gBACX,oBAAC,cAAW,OAAM,QAAO,SAAS,cAAc;AAAA,iBAClD;AAAA,eACF;AAAA;AAAA;AAAA,MACF,GACF;AAAA,OACF;AAAA,KACF;AAEJ;","names":[]}
|
package/dist/infra/api/types.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/infra/api/types.ts"],"sourcesContent":["import z from 'zod';\r\n\r\nexport const PaginationParamsSchema = z.object({\
|
|
1
|
+
{"version":3,"sources":["../../../src/infra/api/types.ts"],"sourcesContent":["import z from 'zod';\r\n\r\nexport const PaginationParamsSchema = z.object({\n page: z.number().min(1).optional().default(1),\n limit: z.number().optional().default(20),\n});\n\r\nexport interface PaginationParams extends z.infer<typeof PaginationParamsSchema> {}\r\n\r\nexport const SearchParamsSchema = z.object({\r\n search: z.string().optional(),\r\n});\r\n\r\nexport interface SearchParams extends z.infer<typeof SearchParamsSchema> {}\r\n\r\nexport const SortParamsSchema = z.object({\r\n sort: z.string().optional(),\r\n});\r\n\r\nexport interface SortParams extends z.infer<typeof SortParamsSchema> {}\r\n\r\nexport interface ApiSuccessResult<T> {\r\n status: 1;\r\n data?: T;\r\n}\r\n\r\nexport interface ApiPaginatedSuccessResult<T> extends Omit<ApiSuccessResult<T>, 'data'> {\r\n data: T[];\r\n total: number;\r\n}\r\n\r\nexport interface ApiErrorResult {\r\n status: 0;\r\n message: string;\r\n}\r\n\r\nexport type ApiActionResult<T> = ApiSuccessResult<T> | ApiErrorResult;\r\nexport type ApiPaginatedActionResult<T> = ApiPaginatedSuccessResult<T> | ApiErrorResult;\r\n\r\nexport interface SuccessResult<T> {\r\n success: true;\r\n data?: T;\r\n total?: number;\r\n}\r\n\r\nexport interface PaginatedSuccessResult<T> extends Omit<SuccessResult<T>, 'data'> {\r\n data: T[];\r\n total: number;\r\n}\r\n\r\nexport interface ErrorResult {\r\n success: false;\r\n error?: string;\r\n}\r\n\r\nexport type ActionResult<T> = SuccessResult<T> | ErrorResult;\r\nexport type PaginatedActionResult<T> = PaginatedSuccessResult<T> | ErrorResult;\r\n\r\nexport class ApiError extends Error {\r\n public readonly code: string;\r\n public readonly statusCode: number;\r\n\r\n constructor(message: string, code: string = 'UNKNOWN_ERROR', statusCode: number = 500) {\r\n super(message);\r\n this.name = 'ApiError';\r\n this.code = code;\r\n this.statusCode = statusCode;\r\n }\r\n\r\n static isApiError(error: unknown): error is ApiError {\r\n return error instanceof ApiError;\r\n }\r\n}\r\n\r\nexport interface ApiResponse<T = unknown> {\r\n status: 0 | 1;\r\n message?: string;\r\n data?: T;\r\n}\r\n"],"mappings":"AAAA,OAAO,OAAO;AAEP,MAAM,yBAAyB,EAAE,OAAO;AAAA,EAC7C,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC;AAAA,EAC5C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE;AACzC,CAAC;AAIM,MAAM,qBAAqB,EAAE,OAAO;AAAA,EACzC,QAAQ,EAAE,OAAO,EAAE,SAAS;AAC9B,CAAC;AAIM,MAAM,mBAAmB,EAAE,OAAO;AAAA,EACvC,MAAM,EAAE,OAAO,EAAE,SAAS;AAC5B,CAAC;AAyCM,MAAM,iBAAiB,MAAM;AAAA,EAClB;AAAA,EACA;AAAA,EAEhB,YAAY,SAAiB,OAAe,iBAAiB,aAAqB,KAAK;AACrF,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,aAAa;AAAA,EACpB;AAAA,EAEA,OAAO,WAAW,OAAmC;AACnD,WAAO,iBAAiB;AAAA,EAC1B;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -46,13 +46,9 @@ function ProfilePopover({
|
|
|
46
46
|
const router = useRouter();
|
|
47
47
|
|
|
48
48
|
const handleLogout = async () => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
await logout();
|
|
53
|
-
} finally {
|
|
54
|
-
setIsLoggingOut(false);
|
|
55
|
-
}
|
|
49
|
+
setPopoverOpen(false);
|
|
50
|
+
setIsLoggingOut(true);
|
|
51
|
+
await logout();
|
|
56
52
|
};
|
|
57
53
|
|
|
58
54
|
const hasSubscription = !isSubscriptionLoading && subscription !== null;
|
|
@@ -117,7 +113,7 @@ function ProfilePopover({
|
|
|
117
113
|
const isSameOrigin = accountsUrl.startsWith(window.location.origin);
|
|
118
114
|
if (isSameOrigin) {
|
|
119
115
|
setPopoverOpen(false);
|
|
120
|
-
router.push(`${
|
|
116
|
+
router.push(`${window.location.pathname}?openProfile=true`);
|
|
121
117
|
} else {
|
|
122
118
|
window.location.href = `${accountsUrl}?openProfile=true`;
|
|
123
119
|
}
|
package/src/infra/api/types.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
|
|
3
|
-
export const PaginationParamsSchema = z.object({
|
|
4
|
-
page: z.number().min(1).optional().default(
|
|
5
|
-
limit: z.number().optional().default(20),
|
|
6
|
-
});
|
|
3
|
+
export const PaginationParamsSchema = z.object({
|
|
4
|
+
page: z.number().min(1).optional().default(1),
|
|
5
|
+
limit: z.number().optional().default(20),
|
|
6
|
+
});
|
|
7
7
|
|
|
8
8
|
export interface PaginationParams extends z.infer<typeof PaginationParamsSchema> {}
|
|
9
9
|
|