@yeverlibs/ds 1.1.13 → 1.1.15

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/index.mjs CHANGED
@@ -2,27 +2,24 @@ import { clsx } from 'clsx';
2
2
  import { twMerge } from 'tailwind-merge';
3
3
  import * as React107 from 'react';
4
4
  import React107__default, { forwardRef, createContext, useState, useEffect, memo, useCallback, useContext, useRef, Suspense } from 'react';
5
- import { usePathname, useRouter, useSearchParams, redirect } from 'next/navigation';
5
+ import { usePathname, useRouter, useSearchParams } from 'next/navigation';
6
6
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
7
7
  import tw5 from 'tailwind-styled-components';
8
- import Image4 from 'next/image';
8
+ import Image3 from 'next/image';
9
9
  import ReactDOM from 'react-dom';
10
- import { toast } from 'sonner';
11
- import { revalidatePath } from 'next/cache';
12
- import { headers } from 'next/headers';
13
- import Cookies from 'js-cookie';
14
10
  import Select from 'react-select';
15
11
  import { isValid, format, parse, startOfMonth, subMonths, endOfMonth, subDays, startOfDay, endOfDay, startOfWeek, endOfWeek, addDays, isWithinInterval, isSameDay, addMonths } from 'date-fns';
16
12
  import { ptBR } from 'date-fns/locale';
17
13
  import { useFormContext, Controller, useForm, FormProvider, useWatch } from 'react-hook-form';
18
14
  import Link2 from 'next/link';
19
15
  import { AnimatePresence, motion } from 'framer-motion';
16
+ import { toast } from 'sonner';
20
17
  import { ResponsiveBar } from '@nivo/bar';
21
18
  import { ResponsiveLine } from '@nivo/line';
22
19
  import { ResponsivePie } from '@nivo/pie';
20
+ import Cookies from 'js-cookie';
23
21
  import currency from 'currency.js';
24
22
 
25
- // src/lib/utils.ts
26
23
  function cn(...inputs) {
27
24
  return twMerge(clsx(inputs));
28
25
  }
@@ -3405,7 +3402,7 @@ var Avatar = ({ name, src, size = "large", className }) => {
3405
3402
  size === "xlarge" && "h-[44px] min-w-[44px]",
3406
3403
  className
3407
3404
  ),
3408
- children: src ? /* @__PURE__ */ jsx(Image4, { src, alt: name || "Avatar", layout: "fill", className: "object-cover" }) : /* @__PURE__ */ jsx("div", { className: "flex h-full w-full items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: cn("font-medium text-white", size === "small" && "text-xs", size === "large" && "text-2xl"), children: getInitials(name) }) })
3405
+ children: src ? /* @__PURE__ */ jsx(Image3, { src, alt: name || "Avatar", layout: "fill", className: "object-cover" }) : /* @__PURE__ */ jsx("div", { className: "flex h-full w-full items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: cn("font-medium text-white", size === "small" && "text-xs", size === "large" && "text-2xl"), children: getInitials(name) }) })
3409
3406
  }
3410
3407
  );
3411
3408
  };
@@ -3930,603 +3927,142 @@ var CheckboxGroup = ({
3930
3927
  ] });
3931
3928
  };
3932
3929
  var checkbox_group_default = CheckboxGroup;
3933
- var ModalContainer = ({ isOpen, onClose, className, children }) => {
3934
- const [isVisible, setIsVisible] = useState(false);
3935
- const [isMounted, setIsMounted] = useState(false);
3936
- useEffect(() => {
3937
- setIsMounted(true);
3938
- }, []);
3939
- useEffect(() => {
3940
- if (isOpen) {
3941
- document.documentElement.classList.add("no-scroll-modal");
3942
- setIsVisible(true);
3943
- } else {
3944
- document.documentElement.classList.remove("no-scroll-modal");
3945
- setIsVisible(false);
3930
+ var DropdownContext = createContext({
3931
+ isOpen: false,
3932
+ toggleDropdown: () => void 0,
3933
+ closeDropdown: () => void 0
3934
+ });
3935
+ var DropdownContainer = ({ children, ...props }) => {
3936
+ return /* @__PURE__ */ jsx(Box, { className: "relative", ...props, children });
3937
+ };
3938
+ var ButtonAction = ({ children, ...props }) => {
3939
+ const context = useContext(DropdownContext);
3940
+ if (!context) {
3941
+ throw new Error("Button must be used within a ButtonTrigger");
3942
+ }
3943
+ const { toggleDropdown } = context;
3944
+ return /* @__PURE__ */ jsx(
3945
+ Button,
3946
+ {
3947
+ $variant: "tertiary",
3948
+ className: "hover:bg-transparent min-h-8 min-w-8 border-none p-0",
3949
+ onClick: toggleDropdown,
3950
+ ...props,
3951
+ children
3946
3952
  }
3947
- }, [isOpen]);
3953
+ );
3954
+ };
3955
+ var DropdownContent = ({ children, ...props }) => {
3956
+ const { className } = props;
3957
+ return /* @__PURE__ */ jsx(Box, { ...props, className: cn("absolute right-0 overflow-x-hidden !p-0", className), children });
3958
+ };
3959
+ var DropdownContentHeader = ({ children, ...props }) => {
3960
+ const { className } = props;
3961
+ return /* @__PURE__ */ jsx("div", { ...props, className: cn("border-b border-gray-300", className), children });
3962
+ };
3963
+ var DropdownContentFooter = ({ children, ...props }) => {
3964
+ return /* @__PURE__ */ jsx("div", { ...props, children });
3965
+ };
3966
+ var DropdownTrigger = ({ children, ...props }) => {
3967
+ const [isOpen, setIsOpen] = useState(false);
3968
+ const containerRef = useRef(null);
3969
+ const toggleDropdown = () => {
3970
+ setIsOpen((prev) => !prev);
3971
+ };
3972
+ const closeDropdown = () => {
3973
+ setIsOpen(false);
3974
+ };
3948
3975
  useEffect(() => {
3949
- const handleEsc = (event) => {
3950
- if (event.key === "Escape") {
3951
- onClose();
3976
+ const handleClickOutside = (event) => {
3977
+ if (containerRef.current && !containerRef.current.contains(event.target)) {
3978
+ closeDropdown();
3952
3979
  }
3953
3980
  };
3954
- window.addEventListener("keydown", handleEsc);
3981
+ document.addEventListener("mousedown", handleClickOutside);
3955
3982
  return () => {
3956
- window.removeEventListener("keydown", handleEsc);
3983
+ document.removeEventListener("mousedown", handleClickOutside);
3957
3984
  };
3958
- }, [onClose]);
3959
- if (!isMounted) return null;
3960
- const portalContainer = document.getElementById("portal-root");
3961
- if (!portalContainer) return null;
3962
- return ReactDOM.createPortal(
3963
- /* @__PURE__ */ jsxs(
3964
- "div",
3965
- {
3966
- className: cn(
3967
- "fixed inset-0 z-[60] flex items-center justify-center",
3968
- isOpen ? "opacity-100" : "opacity-0",
3969
- isVisible ? "pointer-events-auto" : "pointer-events-none",
3970
- "transition-opacity duration-300 md:mx-auto",
3971
- className
3972
- ),
3973
- children: [
3974
- /* @__PURE__ */ jsx("div", { className: "fixed inset-0 bg-black bg-opacity-50", onClick: onClose }),
3975
- /* @__PURE__ */ jsx(
3976
- "div",
3977
- {
3978
- className: cn(
3979
- "shadow-lg z-10 w-full transform overflow-hidden rounded-lg bg-white transition-transform duration-300",
3980
- isOpen ? "scale-100" : "scale-95",
3981
- className ? className : "max-w-lg"
3982
- ),
3983
- style: { margin: "1rem" },
3984
- children
3985
- }
3986
- )
3987
- ]
3988
- }
3989
- ),
3990
- portalContainer
3991
- );
3985
+ }, [containerRef]);
3986
+ return /* @__PURE__ */ jsx(DropdownContext.Provider, { value: { isOpen, toggleDropdown, closeDropdown }, children: /* @__PURE__ */ jsx("div", { ref: containerRef, className: "relative w-full", ...props, children }) });
3992
3987
  };
3993
- var ModalHeader = ({ children, onClose, className = "" }) => /* @__PURE__ */ jsxs("div", { className: cn("relative flex items-center justify-between border-b border-gray-300 px-6 pb-4 pt-6", className), children: [
3994
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between gap-3", children }),
3995
- /* @__PURE__ */ jsx(
3996
- Button,
3988
+ var DrowpdownButton = {
3989
+ Container: DropdownContainer,
3990
+ Button: ButtonAction,
3991
+ Content: DropdownContent,
3992
+ Header: DropdownContentHeader,
3993
+ Footer: DropdownContentFooter
3994
+ };
3995
+ var DropdownItens = ({ items }) => {
3996
+ return /* @__PURE__ */ jsx(Box, { className: "flex w-full min-w-[230px] flex-col justify-end p-0 shadow-base", children: items.map((item, index) => {
3997
+ const isFirst = index === 0;
3998
+ const isLast = index === items.length - 1;
3999
+ const borderRadiusClass = isFirst ? "rounded-t-md" : isLast ? "rounded-b-md" : "!rounded-none";
4000
+ return React107__default.cloneElement(item, {
4001
+ className: `${item.props.className} ${borderRadiusClass} border-b border-gray-200`,
4002
+ key: index
4003
+ });
4004
+ }) });
4005
+ };
4006
+ var FeedbackBadge = ({
4007
+ children,
4008
+ $variant,
4009
+ customClassName,
4010
+ tagColor,
4011
+ tagTextColor,
4012
+ ...props
4013
+ }) => {
4014
+ const { onClick } = props;
4015
+ const inlineStyles = {
4016
+ backgroundColor: tagColor,
4017
+ color: tagTextColor,
4018
+ borderColor: tagColor
4019
+ };
4020
+ return /* @__PURE__ */ jsx(
4021
+ "div",
3997
4022
  {
3998
- onClick: onClose,
3999
- $variant: "tertiary",
4000
- className: "absolute right-4 top-4 w-auto border-none p-0",
4001
- type: "button",
4002
- children: /* @__PURE__ */ jsx(CloseIcon_default, {})
4023
+ className: cn(
4024
+ "flex w-fit items-center justify-center rounded border px-2 py-1 text-xs font-medium",
4025
+ onClick && "cursor-pointer",
4026
+ customClassName,
4027
+ {
4028
+ "border-green-100 bg-green-0 text-green-800": $variant === "success",
4029
+ "border-orange-100 bg-orange-0 text-orange-800": $variant === "warning",
4030
+ "border-yellow-600 bg-orange-0 text-orange-100": $variant === "risk",
4031
+ "border-red-100 bg-red-0 text-red-800": $variant === "error",
4032
+ "border-gray-300 bg-gray-0 text-black": $variant === "default",
4033
+ "cursor-pointer border-orange-1000 bg-orange-1000 font-bold text-white": $variant === "ribbon"
4034
+ }
4035
+ ),
4036
+ onClick,
4037
+ style: inlineStyles,
4038
+ ...props,
4039
+ children
4003
4040
  }
4004
- )
4005
- ] });
4006
- var ModalContent = ({ children, className = "" }) => /* @__PURE__ */ jsx("div", { className: cn("px-8 py-6", className), children });
4007
- var ModalFooter = ({ children, className = "" }) => /* @__PURE__ */ jsx("div", { className: cn("flex border-t border-gray-300 px-6 py-4", className), children });
4008
- var Modal = {
4009
- Container: ModalContainer,
4010
- Header: ModalHeader,
4011
- Content: ModalContent,
4012
- Footer: ModalFooter
4013
- };
4014
-
4015
- // src/_design-system/typography/heading/styles.ts
4016
- var headingStyles = {
4017
- h1: "text-2xl font-semibold text-black",
4018
- h2: "text-lg font-semibold text-black",
4019
- h3: "text-lg font-semibold text-black",
4020
- h4: "text-base font-semibold text-black",
4021
- h5: "text-sm font-semibold text-black",
4022
- h6: ""
4041
+ );
4023
4042
  };
4024
- var Heading = ({ $as: Tag, children, className = "", tooltip }) => {
4025
- return /* @__PURE__ */ jsxs(Tag, { className: cn(headingStyles[Tag], className, tooltip ? "flex items-center gap-2" : ""), children: [
4026
- children,
4027
- tooltip ? /* @__PURE__ */ jsx(Tooltip, { text: tooltip }) : null
4028
- ] });
4043
+ var FilterListContext = createContext({
4044
+ isOpen: false,
4045
+ toggleDropdown: () => void 0,
4046
+ closeDropdown: () => void 0
4047
+ });
4048
+ var FilterContainer = ({ children }) => {
4049
+ return /* @__PURE__ */ jsx(Box, { className: "w-full p-0", children });
4029
4050
  };
4030
-
4031
- // src/_design-system/typography/text/styles.ts
4032
- var textStyles = {
4033
- p: "text-base font-normal text-gray-600",
4034
- span: "text-sm font-medium text-gray-600",
4035
- div: "",
4036
- small: "text-sm font-normal text-gray-600",
4037
- label: "text-sm font-medium text-gray-600"
4051
+ var FilterHeader = ({ children }) => {
4052
+ return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between rounded-t-lg border-b border-gray-300 bg-gray-0 p-4", children });
4038
4053
  };
4039
- var Text = ({ $as: Tag, children, className = "", ...props }) => {
4040
- const elementProps = {
4041
- className: cn(textStyles[Tag], className),
4042
- ...props
4043
- };
4044
- return /* @__PURE__ */ jsx(Tag, { ...elementProps, children });
4054
+ var FilterContent = ({ children }) => {
4055
+ return /* @__PURE__ */ jsx("div", { id: "select-filters", className: "z-10 flex max-h-[280px] flex-col gap-4 overflow-y-auto p-6", children });
4045
4056
  };
4046
- async function handleFormSubmission({
4047
- id,
4048
- createAction,
4049
- updateAction,
4050
- customAction,
4051
- successMessages,
4052
- onSuccess
4053
- }) {
4054
- let result = null;
4055
- let message = null;
4056
- if (customAction) {
4057
- result = await customAction();
4058
- message = successMessages?.custom || "";
4059
- } else {
4060
- if (id) {
4061
- if (updateAction) {
4062
- result = await updateAction();
4063
- message = successMessages?.update || "";
4064
- }
4065
- } else {
4066
- if (createAction) {
4067
- result = await createAction();
4068
- message = successMessages?.create || "";
4069
- }
4070
- }
4071
- }
4072
- if (result && typeof result === "object") {
4073
- const errorData = result.props?.error || result.error;
4074
- if (errorData) {
4075
- if (errorData?.status === 422 && errorData?.errors) {
4076
- Object.values(errorData.errors).forEach((errorMessages) => {
4077
- if (Array.isArray(errorMessages)) {
4078
- errorMessages.forEach((message2) => {
4079
- if (message2.trim()) {
4080
- toast.error(message2.trim());
4081
- }
4082
- });
4083
- } else if (typeof errorMessages === "string") {
4084
- toast.error(errorMessages);
4085
- }
4086
- });
4087
- return null;
4088
- }
4089
- if (errorData?.message) {
4090
- toast.error(errorData.message);
4091
- return null;
4092
- }
4093
- }
4094
- }
4095
- if (message) {
4096
- toast.success(message);
4097
- }
4098
- if (onSuccess) {
4099
- onSuccess(result);
4100
- }
4101
- return result;
4102
- }
4103
- async function getCsrfToken() {
4104
- const baseURL = process.env.NEXT_PUBLIC_API_URL ?? "http://api.yever.local";
4105
- const response = await fetch(`${baseURL}/sanctum/csrf-cookie`, {
4106
- credentials: "include",
4107
- headers: {
4108
- "X-Requested-With": "XMLHttpRequest"
4109
- }
4110
- });
4111
- if (!response.ok) {
4112
- throw new Error("Falha ao obter token CSRF");
4113
- }
4114
- await new Promise((resolve) => setTimeout(resolve, 100));
4115
- }
4116
- async function apiFetch(options) {
4117
- const baseURL = process.env.NEXT_PUBLIC_API_URL ?? "";
4118
- const isAbsolute = /^https?:\/\//i.test(options.url);
4119
- const url = isAbsolute ? options.url : `${baseURL}${options.url}`;
4120
- const method = (options.method ?? "GET").toString().toLowerCase();
4121
- const needsCSRFToken = ["post", "put", "delete"].includes(method);
4122
- const hasCSRFCookie = Cookies.get("XSRF-TOKEN");
4123
- if (needsCSRFToken && !hasCSRFCookie) {
4124
- await getCsrfToken();
4125
- }
4126
- const defaultHeaders = {
4127
- "X-Requested-With": "XMLHttpRequest",
4128
- Accept: "application/json"
4129
- };
4130
- if (!(options.body instanceof FormData)) {
4131
- defaultHeaders["Content-Type"] = "application/json";
4132
- }
4133
- const finalHeaders = new Headers(defaultHeaders);
4134
- if (options.headers) {
4135
- if (options.headers instanceof Headers) {
4136
- options.headers.forEach((v, k) => finalHeaders.set(k, v));
4137
- } else {
4138
- Object.entries(options.headers).forEach(([k, v]) => {
4139
- if (v !== void 0) finalHeaders.set(k, v);
4140
- });
4141
- }
4142
- }
4143
- const csrfToken = Cookies.get("XSRF-TOKEN");
4144
- if (csrfToken) {
4145
- finalHeaders.set("X-XSRF-TOKEN", csrfToken);
4146
- }
4147
- let finalOptions = options;
4148
- if (options.body) {
4149
- finalOptions = {
4150
- ...options,
4151
- body: options.body instanceof FormData ? options.body : JSON.stringify(options.body)
4152
- };
4153
- }
4154
- let response = await fetch(url, {
4155
- credentials: "include",
4156
- headers: finalHeaders,
4157
- ...finalOptions
4158
- });
4159
- if (response.status === 419) {
4160
- Cookies.remove("XSRF-TOKEN");
4161
- await getCsrfToken();
4162
- const newToken = Cookies.get("XSRF-TOKEN");
4163
- if (newToken) {
4164
- finalHeaders.set("X-XSRF-TOKEN", newToken);
4165
- }
4166
- response = await fetch(url, {
4167
- credentials: "include",
4168
- headers: finalHeaders,
4169
- ...options
4170
- });
4171
- if (!response.ok) {
4172
- Cookies.remove("XSRF-TOKEN");
4173
- Cookies.remove("yeverClientUser");
4174
- window.location.href = "/login";
4175
- return Promise.reject(new Error("CSRF token expirado"));
4176
- }
4177
- }
4178
- const headers2 = {};
4179
- response.headers.forEach((value, key) => {
4180
- headers2[key] = value;
4181
- });
4182
- if (!response.ok) {
4183
- const data2 = await response.json().catch(() => null);
4184
- const errorMessage = typeof data2 === "object" && data2 !== null && "message" in data2 ? data2.message : "Request failed";
4185
- const error = new Error(errorMessage);
4186
- error.status = response.status;
4187
- error.response = {
4188
- data: data2,
4189
- status: response.status
4190
- };
4191
- throw error;
4192
- }
4193
- let data = null;
4194
- if (options.responseType === "blob") {
4195
- data = await response.blob().catch(() => null);
4196
- } else {
4197
- data = await response.json().catch(() => null);
4198
- }
4199
- return {
4200
- status: response.status,
4201
- statusText: response.statusText,
4202
- data,
4203
- headers: headers2
4204
- };
4205
- }
4206
-
4207
- // src/utils/parse-parameters-into-url/index.tsx
4208
- var parseParametersIntoUrl = (url, query, filtersAllowed) => {
4209
- let urlFiltered = url;
4210
- for (const key in query) {
4211
- if (query && Object.keys(query).length > 0) {
4212
- urlFiltered = urlFiltered.replace(`/${key}/`, `/${query[key]}/`);
4213
- urlFiltered = urlFiltered.replace(`/${key}`, `/${query[key]}`);
4214
- if (filtersAllowed && filtersAllowed.includes(key)) {
4215
- if (urlFiltered.includes("?")) {
4216
- if (key === "searchNew") {
4217
- urlFiltered = urlFiltered + `&${key}=${atob(query[key])}`;
4218
- } else {
4219
- urlFiltered = urlFiltered + `&${key}=${query[key]}`;
4220
- }
4221
- } else {
4222
- if (key === "searchNew") {
4223
- urlFiltered = urlFiltered + `?${key}=${atob(query[key])}`;
4224
- } else {
4225
- urlFiltered = urlFiltered + `?${key}=${query[key]}`;
4226
- }
4227
- }
4228
- }
4229
- }
4230
- }
4231
- return urlFiltered;
4232
- };
4233
-
4234
- // src/lib/fetch-server-side/index.ts
4235
- var fetchServerSide = async ({
4236
- urlRequest,
4237
- parseData,
4238
- filtersAllowed,
4239
- method = "GET",
4240
- body
4241
- }) => {
4242
- "use server";
4243
- try {
4244
- const headersObject = Object.fromEntries((await headers()).entries());
4245
- const searchParams = new URLSearchParams(headersObject.referer ? new URL(headersObject.referer).search : "");
4246
- const query = Array.from(searchParams.entries()).reduce((acc, [key, value]) => {
4247
- acc[key] = value;
4248
- return acc;
4249
- }, {});
4250
- const url = parseParametersIntoUrl(urlRequest, query, filtersAllowed);
4251
- const origin = headersObject.host;
4252
- const cookie = headersObject.cookie;
4253
- const xsrfToken = cookie?.match(/XSRF-TOKEN=([^;]+)/)?.[1];
4254
- const requestHeaders = {
4255
- Cookie: cookie,
4256
- origin
4257
- };
4258
- if (xsrfToken) {
4259
- requestHeaders["X-XSRF-TOKEN"] = decodeURIComponent(xsrfToken);
4260
- }
4261
- let pagination;
4262
- const res = await apiFetch({
4263
- url,
4264
- method,
4265
- body,
4266
- headers: requestHeaders,
4267
- cache: "no-store"
4268
- });
4269
- if (res?.data && typeof res.data === "object" && "paginate" in res.data) {
4270
- pagination = res.data.paginate;
4271
- }
4272
- const parsedData = parseData ? parseData(res) : res;
4273
- return {
4274
- props: {
4275
- pagination,
4276
- data: parsedData
4277
- }
4278
- };
4279
- } catch (error) {
4280
- const apiError = error;
4281
- switch (apiError.response?.status) {
4282
- case 401:
4283
- redirect("/login");
4284
- case 403:
4285
- return {
4286
- props: {
4287
- error: {
4288
- status: 403,
4289
- message: "Voc\xEA n\xE3o tem permiss\xE3o para executar essa a\xE7\xE3o",
4290
- errors: {}
4291
- },
4292
- data: null
4293
- }
4294
- };
4295
- case 404:
4296
- return {
4297
- props: {
4298
- error: {
4299
- status: 404,
4300
- message: apiError.response.data?.message || "Recurso n\xE3o encontrado",
4301
- errors: apiError.response?.data?.errors || {}
4302
- },
4303
- data: null
4304
- }
4305
- };
4306
- case 422:
4307
- return {
4308
- props: {
4309
- error: {
4310
- status: 422,
4311
- message: apiError.response.data?.message || "Erro de valida\xE7\xE3o",
4312
- errors: apiError.response?.data?.errors
4313
- }
4314
- }
4315
- };
4316
- case 500:
4317
- return {
4318
- props: {
4319
- error: {
4320
- status: 500,
4321
- message: apiError.response.data?.message || "Ocorreu um erro durante o processamento dessa requisi\xE7\xE3o. A Yever foi notificada e estamos atuando para sanar o problema.",
4322
- errors: {}
4323
- }
4324
- }
4325
- };
4326
- default:
4327
- if (apiError.response?.data?.errors || apiError.response?.data?.message) {
4328
- return {
4329
- props: {
4330
- error: {
4331
- status: apiError.response.status,
4332
- message: apiError.response.data?.message,
4333
- errors: apiError.response.data?.errors
4334
- }
4335
- }
4336
- };
4337
- }
4338
- redirect("/500");
4339
- }
4340
- }
4341
- };
4342
-
4343
- // src/_design-system/delete-modal/_actions/index.ts
4344
- async function deleteFunc(endpoint, location) {
4345
- const response = await fetchServerSide({
4346
- urlRequest: endpoint,
4347
- method: "DELETE"
4348
- });
4349
- revalidatePath(location);
4350
- return response;
4351
- }
4352
- var DeleteModal = ({
4353
- isModalOpen,
4354
- setIsModalOpen,
4355
- endpoint,
4356
- successMessage,
4357
- location,
4358
- title,
4359
- message,
4360
- onSuccess
4361
- }) => {
4362
- const [loading, setLoading] = useState(false);
4363
- const router = useRouter();
4364
- const handleSubmit = async () => {
4365
- setLoading(true);
4366
- await handleFormSubmission({
4367
- customAction: () => deleteFunc(endpoint, location),
4368
- successMessages: {
4369
- custom: successMessage || "Item deletado com sucesso"
4370
- },
4371
- onSuccess: () => {
4372
- setIsModalOpen(false);
4373
- if (onSuccess) {
4374
- onSuccess();
4375
- } else {
4376
- router.push(location);
4377
- }
4378
- }
4379
- });
4380
- setLoading(false);
4381
- };
4382
- return /* @__PURE__ */ jsxs(Modal.Container, { isOpen: isModalOpen, onClose: () => setIsModalOpen(false), className: "max-w-[590px]", children: [
4383
- /* @__PURE__ */ jsxs(Modal.Header, { onClose: () => setIsModalOpen(false), children: [
4384
- /* @__PURE__ */ jsx(Image4, { src: "/images/modal-delete-icon.svg", alt: "Secure", width: 40, height: 40 }),
4385
- /* @__PURE__ */ jsx(Heading, { $as: "h3", children: title })
4386
- ] }),
4387
- /* @__PURE__ */ jsx(Modal.Content, { children: /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-6", children: /* @__PURE__ */ jsx(Text, { $as: "p", children: message }) }) }),
4388
- /* @__PURE__ */ jsxs(Modal.Footer, { className: "flex items-center justify-end gap-4", children: [
4389
- /* @__PURE__ */ jsx(Button, { $variant: "tertiary", onClick: () => setIsModalOpen(false), className: "w-fit", disabled: loading, children: "Cancelar" }),
4390
- /* @__PURE__ */ jsx(Button, { className: "w-fit", $variant: "warning", onClick: handleSubmit, disabled: loading, $isLoading: loading, children: "Remover" })
4391
- ] })
4392
- ] });
4393
- };
4394
- var DropdownContext = createContext({
4395
- isOpen: false,
4396
- toggleDropdown: () => void 0,
4397
- closeDropdown: () => void 0
4398
- });
4399
- var DropdownContainer = ({ children, ...props }) => {
4400
- return /* @__PURE__ */ jsx(Box, { className: "relative", ...props, children });
4401
- };
4402
- var ButtonAction = ({ children, ...props }) => {
4403
- const context = useContext(DropdownContext);
4404
- if (!context) {
4405
- throw new Error("Button must be used within a ButtonTrigger");
4406
- }
4407
- const { toggleDropdown } = context;
4408
- return /* @__PURE__ */ jsx(
4409
- Button,
4410
- {
4411
- $variant: "tertiary",
4412
- className: "hover:bg-transparent min-h-8 min-w-8 border-none p-0",
4413
- onClick: toggleDropdown,
4414
- ...props,
4415
- children
4416
- }
4417
- );
4418
- };
4419
- var DropdownContent = ({ children, ...props }) => {
4420
- const { className } = props;
4421
- return /* @__PURE__ */ jsx(Box, { ...props, className: cn("absolute right-0 overflow-x-hidden !p-0", className), children });
4422
- };
4423
- var DropdownContentHeader = ({ children, ...props }) => {
4424
- const { className } = props;
4425
- return /* @__PURE__ */ jsx("div", { ...props, className: cn("border-b border-gray-300", className), children });
4426
- };
4427
- var DropdownContentFooter = ({ children, ...props }) => {
4428
- return /* @__PURE__ */ jsx("div", { ...props, children });
4429
- };
4430
- var DropdownTrigger = ({ children, ...props }) => {
4431
- const [isOpen, setIsOpen] = useState(false);
4432
- const containerRef = useRef(null);
4433
- const toggleDropdown = () => {
4434
- setIsOpen((prev) => !prev);
4435
- };
4436
- const closeDropdown = () => {
4437
- setIsOpen(false);
4438
- };
4439
- useEffect(() => {
4440
- const handleClickOutside = (event) => {
4441
- if (containerRef.current && !containerRef.current.contains(event.target)) {
4442
- closeDropdown();
4443
- }
4444
- };
4445
- document.addEventListener("mousedown", handleClickOutside);
4446
- return () => {
4447
- document.removeEventListener("mousedown", handleClickOutside);
4448
- };
4449
- }, [containerRef]);
4450
- return /* @__PURE__ */ jsx(DropdownContext.Provider, { value: { isOpen, toggleDropdown, closeDropdown }, children: /* @__PURE__ */ jsx("div", { ref: containerRef, className: "relative w-full", ...props, children }) });
4451
- };
4452
- var DrowpdownButton = {
4453
- Container: DropdownContainer,
4454
- Button: ButtonAction,
4455
- Content: DropdownContent,
4456
- Header: DropdownContentHeader,
4457
- Footer: DropdownContentFooter
4458
- };
4459
- var DropdownItens = ({ items }) => {
4460
- return /* @__PURE__ */ jsx(Box, { className: "flex w-full min-w-[230px] flex-col justify-end p-0 shadow-base", children: items.map((item, index) => {
4461
- const isFirst = index === 0;
4462
- const isLast = index === items.length - 1;
4463
- const borderRadiusClass = isFirst ? "rounded-t-md" : isLast ? "rounded-b-md" : "!rounded-none";
4464
- return React107__default.cloneElement(item, {
4465
- className: `${item.props.className} ${borderRadiusClass} border-b border-gray-200`,
4466
- key: index
4467
- });
4468
- }) });
4469
- };
4470
- var FeedbackBadge = ({
4471
- children,
4472
- $variant,
4473
- customClassName,
4474
- tagColor,
4475
- tagTextColor,
4476
- ...props
4477
- }) => {
4478
- const { onClick } = props;
4479
- const inlineStyles = {
4480
- backgroundColor: tagColor,
4481
- color: tagTextColor,
4482
- borderColor: tagColor
4483
- };
4484
- return /* @__PURE__ */ jsx(
4485
- "div",
4486
- {
4487
- className: cn(
4488
- "flex w-fit items-center justify-center rounded border px-2 py-1 text-xs font-medium",
4489
- onClick && "cursor-pointer",
4490
- customClassName,
4491
- {
4492
- "border-green-100 bg-green-0 text-green-800": $variant === "success",
4493
- "border-orange-100 bg-orange-0 text-orange-800": $variant === "warning",
4494
- "border-yellow-600 bg-orange-0 text-orange-100": $variant === "risk",
4495
- "border-red-100 bg-red-0 text-red-800": $variant === "error",
4496
- "border-gray-300 bg-gray-0 text-black": $variant === "default",
4497
- "cursor-pointer border-orange-1000 bg-orange-1000 font-bold text-white": $variant === "ribbon"
4498
- }
4499
- ),
4500
- onClick,
4501
- style: inlineStyles,
4502
- ...props,
4503
- children
4504
- }
4505
- );
4506
- };
4507
- var FilterListContext = createContext({
4508
- isOpen: false,
4509
- toggleDropdown: () => void 0,
4510
- closeDropdown: () => void 0
4511
- });
4512
- var FilterContainer = ({ children }) => {
4513
- return /* @__PURE__ */ jsx(Box, { className: "w-full p-0", children });
4514
- };
4515
- var FilterHeader = ({ children }) => {
4516
- return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between rounded-t-lg border-b border-gray-300 bg-gray-0 p-4", children });
4517
- };
4518
- var FilterContent = ({ children }) => {
4519
- return /* @__PURE__ */ jsx("div", { id: "select-filters", className: "z-10 flex max-h-[280px] flex-col gap-4 overflow-y-auto p-6", children });
4520
- };
4521
- var FilterFooter = ({ children, className }) => {
4522
- return /* @__PURE__ */ jsx(
4523
- "div",
4524
- {
4525
- className: cn(
4526
- "flex flex-col justify-between gap-3 rounded-b-lg border-t border-gray-300 bg-gray-0 p-4 px-6",
4527
- className
4528
- ),
4529
- children
4057
+ var FilterFooter = ({ children, className }) => {
4058
+ return /* @__PURE__ */ jsx(
4059
+ "div",
4060
+ {
4061
+ className: cn(
4062
+ "flex flex-col justify-between gap-3 rounded-b-lg border-t border-gray-300 bg-gray-0 p-4 px-6",
4063
+ className
4064
+ ),
4065
+ children
4530
4066
  }
4531
4067
  );
4532
4068
  };
@@ -5507,6 +5043,38 @@ var SlidingPanel = {
5507
5043
  Footer: SlidingPanelFooter
5508
5044
  };
5509
5045
 
5046
+ // src/_design-system/typography/heading/styles.ts
5047
+ var headingStyles = {
5048
+ h1: "text-2xl font-semibold text-black",
5049
+ h2: "text-lg font-semibold text-black",
5050
+ h3: "text-lg font-semibold text-black",
5051
+ h4: "text-base font-semibold text-black",
5052
+ h5: "text-sm font-semibold text-black",
5053
+ h6: ""
5054
+ };
5055
+ var Heading = ({ $as: Tag, children, className = "", tooltip }) => {
5056
+ return /* @__PURE__ */ jsxs(Tag, { className: cn(headingStyles[Tag], className, tooltip ? "flex items-center gap-2" : ""), children: [
5057
+ children,
5058
+ tooltip ? /* @__PURE__ */ jsx(Tooltip, { text: tooltip }) : null
5059
+ ] });
5060
+ };
5061
+
5062
+ // src/_design-system/typography/text/styles.ts
5063
+ var textStyles = {
5064
+ p: "text-base font-normal text-gray-600",
5065
+ span: "text-sm font-medium text-gray-600",
5066
+ div: "",
5067
+ small: "text-sm font-normal text-gray-600",
5068
+ label: "text-sm font-medium text-gray-600"
5069
+ };
5070
+ var Text = ({ $as: Tag, children, className = "", ...props }) => {
5071
+ const elementProps = {
5072
+ className: cn(textStyles[Tag], className),
5073
+ ...props
5074
+ };
5075
+ return /* @__PURE__ */ jsx(Tag, { ...elementProps, children });
5076
+ };
5077
+
5510
5078
  // src/utils/next-replace-url/index.ts
5511
5079
  var nextReplaceUrl = (key, value, pathname) => {
5512
5080
  const params = new URLSearchParams(window.location.search);
@@ -6083,6 +5651,87 @@ var Link4 = ({
6083
5651
  }
6084
5652
  );
6085
5653
  };
5654
+ var ModalContainer = ({ isOpen, onClose, className, children }) => {
5655
+ const [isVisible, setIsVisible] = useState(false);
5656
+ const [isMounted, setIsMounted] = useState(false);
5657
+ useEffect(() => {
5658
+ setIsMounted(true);
5659
+ }, []);
5660
+ useEffect(() => {
5661
+ if (isOpen) {
5662
+ document.documentElement.classList.add("no-scroll-modal");
5663
+ setIsVisible(true);
5664
+ } else {
5665
+ document.documentElement.classList.remove("no-scroll-modal");
5666
+ setIsVisible(false);
5667
+ }
5668
+ }, [isOpen]);
5669
+ useEffect(() => {
5670
+ const handleEsc = (event) => {
5671
+ if (event.key === "Escape") {
5672
+ onClose();
5673
+ }
5674
+ };
5675
+ window.addEventListener("keydown", handleEsc);
5676
+ return () => {
5677
+ window.removeEventListener("keydown", handleEsc);
5678
+ };
5679
+ }, [onClose]);
5680
+ if (!isMounted) return null;
5681
+ const portalContainer = document.getElementById("portal-root");
5682
+ if (!portalContainer) return null;
5683
+ return ReactDOM.createPortal(
5684
+ /* @__PURE__ */ jsxs(
5685
+ "div",
5686
+ {
5687
+ className: cn(
5688
+ "fixed inset-0 z-[60] flex items-center justify-center",
5689
+ isOpen ? "opacity-100" : "opacity-0",
5690
+ isVisible ? "pointer-events-auto" : "pointer-events-none",
5691
+ "transition-opacity duration-300 md:mx-auto",
5692
+ className
5693
+ ),
5694
+ children: [
5695
+ /* @__PURE__ */ jsx("div", { className: "fixed inset-0 bg-black bg-opacity-50", onClick: onClose }),
5696
+ /* @__PURE__ */ jsx(
5697
+ "div",
5698
+ {
5699
+ className: cn(
5700
+ "shadow-lg z-10 w-full transform overflow-hidden rounded-lg bg-white transition-transform duration-300",
5701
+ isOpen ? "scale-100" : "scale-95",
5702
+ className ? className : "max-w-lg"
5703
+ ),
5704
+ style: { margin: "1rem" },
5705
+ children
5706
+ }
5707
+ )
5708
+ ]
5709
+ }
5710
+ ),
5711
+ portalContainer
5712
+ );
5713
+ };
5714
+ var ModalHeader = ({ children, onClose, className = "" }) => /* @__PURE__ */ jsxs("div", { className: cn("relative flex items-center justify-between border-b border-gray-300 px-6 pb-4 pt-6", className), children: [
5715
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between gap-3", children }),
5716
+ /* @__PURE__ */ jsx(
5717
+ Button,
5718
+ {
5719
+ onClick: onClose,
5720
+ $variant: "tertiary",
5721
+ className: "absolute right-4 top-4 w-auto border-none p-0",
5722
+ type: "button",
5723
+ children: /* @__PURE__ */ jsx(CloseIcon_default, {})
5724
+ }
5725
+ )
5726
+ ] });
5727
+ var ModalContent = ({ children, className = "" }) => /* @__PURE__ */ jsx("div", { className: cn("px-8 py-6", className), children });
5728
+ var ModalFooter = ({ children, className = "" }) => /* @__PURE__ */ jsx("div", { className: cn("flex border-t border-gray-300 px-6 py-4", className), children });
5729
+ var Modal = {
5730
+ Container: ModalContainer,
5731
+ Header: ModalHeader,
5732
+ Content: ModalContent,
5733
+ Footer: ModalFooter
5734
+ };
6086
5735
 
6087
5736
  // src/_design-system/helpers/formatDateAndReturnPassedHours.ts
6088
5737
  var formatDateAndReturnPassedHours = (date) => {
@@ -6093,7 +5742,7 @@ var formatDateAndReturnPassedHours = (date) => {
6093
5742
  var NotificationItem = ({ user, message, date }) => {
6094
5743
  return /* @__PURE__ */ jsxs("div", { className: "flex cursor-pointer items-start gap-4 px-6 py-4 hover:bg-gray-0", children: [
6095
5744
  /* @__PURE__ */ jsx(
6096
- Image4,
5745
+ Image3,
6097
5746
  {
6098
5747
  src: "/images/yever-notification-avatar.svg",
6099
5748
  width: 49,
@@ -6152,7 +5801,7 @@ var PaymentCard = ({
6152
5801
  /* @__PURE__ */ jsx("span", { className: "font-semibold text-black", children: paymentDate })
6153
5802
  ] })
6154
5803
  ] }),
6155
- /* @__PURE__ */ jsx("div", { className: "flex w-full justify-center sm:w-auto sm:justify-end", children: brand ? /* @__PURE__ */ jsx(Image4, { src: `/images/payments/${brand}.svg`, alt: "brand", width: 60, height: 47 }) : /* @__PURE__ */ jsx(Image4, { src: `/images/payments/others.svg`, alt: "brand", width: 60, height: 47 }) })
5804
+ /* @__PURE__ */ jsx("div", { className: "flex w-full justify-center sm:w-auto sm:justify-end", children: brand ? /* @__PURE__ */ jsx(Image3, { src: `/images/payments/${brand}.svg`, alt: "brand", width: 60, height: 47 }) : /* @__PURE__ */ jsx(Image3, { src: `/images/payments/others.svg`, alt: "brand", width: 60, height: 47 }) })
6156
5805
  ] });
6157
5806
  };
6158
5807
  var PreviewPhone = ({ children, cartPosition = "bottom", bodyColor }) => {
@@ -6709,7 +6358,7 @@ var TableContent = ({
6709
6358
  rowIndex
6710
6359
  )) : /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { colSpan: columns.length + (selectable ? 1 : 0), style: { textAlign: "center" }, children: /* @__PURE__ */ jsxs("div", { className: "py-6", children: [
6711
6360
  /* @__PURE__ */ jsx(
6712
- Image4,
6361
+ Image3,
6713
6362
  {
6714
6363
  src: "/empty-table.svg",
6715
6364
  width: 666,
@@ -6783,15 +6432,15 @@ var TableContent = ({
6783
6432
  var Table = (props) => {
6784
6433
  return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(TableContent, { ...props }) });
6785
6434
  };
6786
- var Tabs = ({ headers: headers2, children, noGap, active, alignDiv = "full" }) => {
6435
+ var Tabs = ({ headers, children, noGap, active, alignDiv = "full" }) => {
6787
6436
  const [activeTab, setActiveTab] = useState(active || 0);
6788
- const flattenHeaders = (headers3) => {
6789
- if (Array.isArray(headers3[0])) {
6790
- return headers3.flat();
6437
+ const flattenHeaders = (headers2) => {
6438
+ if (Array.isArray(headers2[0])) {
6439
+ return headers2.flat();
6791
6440
  }
6792
- return headers3;
6441
+ return headers2;
6793
6442
  };
6794
- const flattenedHeaders = flattenHeaders(headers2);
6443
+ const flattenedHeaders = flattenHeaders(headers);
6795
6444
  return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col", noGap ? "" : "gap-4"), children: [
6796
6445
  /* @__PURE__ */ jsx("div", { className: "flex gap-4 overflow-x-auto overflow-y-hidden border-b border-gray-300", children: flattenedHeaders.map((header, index) => /* @__PURE__ */ jsx(
6797
6446
  "button",
@@ -7174,7 +6823,7 @@ var MultiSelect = ({
7174
6823
  onSelect(newValue);
7175
6824
  };
7176
6825
  const formatOptionLabel = (option) => /* @__PURE__ */ jsxs("div", { className: "flex items-center", children: [
7177
- option.icon && /* @__PURE__ */ jsx("div", { className: "relative mr-2 flex h-[24px] max-h-[24px] w-[24px] max-w-[24px] items-center justify-center rounded border border-gray-300", children: /* @__PURE__ */ jsx(Image4, { src: option.icon, alt: option.label, fill: true, className: "p-1", quality: 100 }) }),
6826
+ option.icon && /* @__PURE__ */ jsx("div", { className: "relative mr-2 flex h-[24px] max-h-[24px] w-[24px] max-w-[24px] items-center justify-center rounded border border-gray-300", children: /* @__PURE__ */ jsx(Image3, { src: option.icon, alt: option.label, fill: true, className: "p-1", quality: 100 }) }),
7178
6827
  /* @__PURE__ */ jsx("span", { className: "text-sm", children: option.label })
7179
6828
  ] });
7180
6829
  return /* @__PURE__ */ jsxs("div", { className: cn("relative w-full", className), children: [
@@ -7262,7 +6911,7 @@ var CustomSelect = ({
7262
6911
  onSelect(option);
7263
6912
  };
7264
6913
  const formatOptionLabel = (option) => /* @__PURE__ */ jsxs("div", { className: "flex items-center", children: [
7265
- option.icon && /* @__PURE__ */ jsx("div", { className: "relative mr-2 flex h-[24px] max-h-[24px] w-[24px] max-w-[24px] items-center justify-center rounded border border-gray-300", children: /* @__PURE__ */ jsx(Image4, { src: option.icon, alt: option.label, fill: true, className: "p-1", quality: 100 }) }),
6914
+ option.icon && /* @__PURE__ */ jsx("div", { className: "relative mr-2 flex h-[24px] max-h-[24px] w-[24px] max-w-[24px] items-center justify-center rounded border border-gray-300", children: /* @__PURE__ */ jsx(Image3, { src: option.icon, alt: option.label, fill: true, className: "p-1", quality: 100 }) }),
7266
6915
  /* @__PURE__ */ jsx("span", { className: "text-sm", children: option.label })
7267
6916
  ] });
7268
6917
  return /* @__PURE__ */ jsxs("div", { className: cn("relative w-full", className), children: [
@@ -8072,7 +7721,7 @@ function FileUploadComponent({
8072
7721
  }
8073
7722
  ) : /* @__PURE__ */ jsx("div", { className: "relative flex h-full w-full items-center justify-center", children: filePreview && isImagePreview(filePreview) ? /* @__PURE__ */ jsxs(Fragment, { children: [
8074
7723
  /* @__PURE__ */ jsx("label", { htmlFor: `${name}-input`, className: "block h-full w-full cursor-pointer", children: /* @__PURE__ */ jsx(
8075
- Image4,
7724
+ Image3,
8076
7725
  {
8077
7726
  src: filePreview,
8078
7727
  alt: "Preview",
@@ -8099,7 +7748,7 @@ function FileUploadComponent({
8099
7748
  ] }) : /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center justify-between gap-4 rounded-md border border-gray-200 bg-white p-4", children: [
8100
7749
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
8101
7750
  /* @__PURE__ */ jsx(
8102
- Image4,
7751
+ Image3,
8103
7752
  {
8104
7753
  src: isPdfFile ? "/icons/pdf.png" : "/icons/xlsx.png",
8105
7754
  alt: "Preview",
@@ -8312,6 +7961,138 @@ var PieChart = ({
8312
7961
  }
8313
7962
  );
8314
7963
  };
7964
+ async function getCsrfToken() {
7965
+ const baseURL = process.env.NEXT_PUBLIC_API_URL ?? "http://api.yever.local";
7966
+ const response = await fetch(`${baseURL}/sanctum/csrf-cookie`, {
7967
+ credentials: "include",
7968
+ headers: {
7969
+ "X-Requested-With": "XMLHttpRequest"
7970
+ }
7971
+ });
7972
+ if (!response.ok) {
7973
+ throw new Error("Falha ao obter token CSRF");
7974
+ }
7975
+ await new Promise((resolve) => setTimeout(resolve, 100));
7976
+ }
7977
+ async function apiFetch(options) {
7978
+ const baseURL = process.env.NEXT_PUBLIC_API_URL ?? "";
7979
+ const isAbsolute = /^https?:\/\//i.test(options.url);
7980
+ const url = isAbsolute ? options.url : `${baseURL}${options.url}`;
7981
+ const method = (options.method ?? "GET").toString().toLowerCase();
7982
+ const needsCSRFToken = ["post", "put", "delete"].includes(method);
7983
+ const hasCSRFCookie = Cookies.get("XSRF-TOKEN");
7984
+ if (needsCSRFToken && !hasCSRFCookie) {
7985
+ await getCsrfToken();
7986
+ }
7987
+ const defaultHeaders = {
7988
+ "X-Requested-With": "XMLHttpRequest",
7989
+ Accept: "application/json"
7990
+ };
7991
+ if (!(options.body instanceof FormData)) {
7992
+ defaultHeaders["Content-Type"] = "application/json";
7993
+ }
7994
+ const finalHeaders = new Headers(defaultHeaders);
7995
+ if (options.headers) {
7996
+ if (options.headers instanceof Headers) {
7997
+ options.headers.forEach((v, k) => finalHeaders.set(k, v));
7998
+ } else {
7999
+ Object.entries(options.headers).forEach(([k, v]) => {
8000
+ if (v !== void 0) finalHeaders.set(k, v);
8001
+ });
8002
+ }
8003
+ }
8004
+ const csrfToken = Cookies.get("XSRF-TOKEN");
8005
+ if (csrfToken) {
8006
+ finalHeaders.set("X-XSRF-TOKEN", csrfToken);
8007
+ }
8008
+ let finalOptions = options;
8009
+ if (options.body) {
8010
+ finalOptions = {
8011
+ ...options,
8012
+ body: options.body instanceof FormData ? options.body : JSON.stringify(options.body)
8013
+ };
8014
+ }
8015
+ let response = await fetch(url, {
8016
+ credentials: "include",
8017
+ headers: finalHeaders,
8018
+ ...finalOptions
8019
+ });
8020
+ if (response.status === 419) {
8021
+ Cookies.remove("XSRF-TOKEN");
8022
+ await getCsrfToken();
8023
+ const newToken = Cookies.get("XSRF-TOKEN");
8024
+ if (newToken) {
8025
+ finalHeaders.set("X-XSRF-TOKEN", newToken);
8026
+ }
8027
+ response = await fetch(url, {
8028
+ credentials: "include",
8029
+ headers: finalHeaders,
8030
+ ...options
8031
+ });
8032
+ if (!response.ok) {
8033
+ Cookies.remove("XSRF-TOKEN");
8034
+ Cookies.remove("yeverClientUser");
8035
+ window.location.href = "/login";
8036
+ return Promise.reject(new Error("CSRF token expirado"));
8037
+ }
8038
+ }
8039
+ const headers = {};
8040
+ response.headers.forEach((value, key) => {
8041
+ headers[key] = value;
8042
+ });
8043
+ if (!response.ok) {
8044
+ const data2 = await response.json().catch(() => null);
8045
+ const errorMessage = typeof data2 === "object" && data2 !== null && "message" in data2 ? data2.message : "Request failed";
8046
+ const error = new Error(errorMessage);
8047
+ error.status = response.status;
8048
+ error.response = {
8049
+ data: data2,
8050
+ status: response.status
8051
+ };
8052
+ throw error;
8053
+ }
8054
+ let data = null;
8055
+ if (options.responseType === "blob") {
8056
+ data = await response.blob().catch(() => null);
8057
+ } else {
8058
+ data = await response.json().catch(() => null);
8059
+ }
8060
+ return {
8061
+ status: response.status,
8062
+ statusText: response.statusText,
8063
+ data,
8064
+ headers
8065
+ };
8066
+ }
8067
+
8068
+ // src/utils/parse-parameters-into-url/index.tsx
8069
+ var parseParametersIntoUrl = (url, query, filtersAllowed) => {
8070
+ let urlFiltered = url;
8071
+ for (const key in query) {
8072
+ if (query && Object.keys(query).length > 0) {
8073
+ urlFiltered = urlFiltered.replace(`/${key}/`, `/${query[key]}/`);
8074
+ urlFiltered = urlFiltered.replace(`/${key}`, `/${query[key]}`);
8075
+ if (filtersAllowed && filtersAllowed.includes(key)) {
8076
+ if (urlFiltered.includes("?")) {
8077
+ if (key === "searchNew") {
8078
+ urlFiltered = urlFiltered + `&${key}=${atob(query[key])}`;
8079
+ } else {
8080
+ urlFiltered = urlFiltered + `&${key}=${query[key]}`;
8081
+ }
8082
+ } else {
8083
+ if (key === "searchNew") {
8084
+ urlFiltered = urlFiltered + `?${key}=${atob(query[key])}`;
8085
+ } else {
8086
+ urlFiltered = urlFiltered + `?${key}=${query[key]}`;
8087
+ }
8088
+ }
8089
+ }
8090
+ }
8091
+ }
8092
+ return urlFiltered;
8093
+ };
8094
+
8095
+ // src/hooks/use-fetch-client-side/index.tsx
8315
8096
  var noopLoading = {
8316
8097
  loadingActions: {
8317
8098
  setLoading: () => {
@@ -8372,22 +8153,22 @@ function useFetchClientSide({
8372
8153
  if (body instanceof FormData) {
8373
8154
  delete configHeaders["Content-Type"];
8374
8155
  }
8375
- const headers2 = {
8156
+ const headers = {
8376
8157
  "X-Requested-With": "XMLHttpRequest",
8377
8158
  Accept: "application/json",
8378
8159
  ...configHeaders
8379
8160
  };
8380
8161
  if (body && !(body instanceof FormData)) {
8381
- headers2["Content-Type"] = "application/json";
8162
+ headers["Content-Type"] = "application/json";
8382
8163
  }
8383
8164
  if (csrfToken) {
8384
- headers2["X-XSRF-TOKEN"] = decodeURIComponent(csrfToken);
8165
+ headers["X-XSRF-TOKEN"] = decodeURIComponent(csrfToken);
8385
8166
  }
8386
8167
  const response = await apiFetch({
8387
8168
  url: customUrl || urlFiltered,
8388
8169
  method: customMethod || method,
8389
8170
  body,
8390
- headers: headers2,
8171
+ headers,
8391
8172
  credentials: "include",
8392
8173
  signal,
8393
8174
  responseType: config?.responseType
@@ -10027,6 +9808,63 @@ var shadow = {
10027
9808
  store: "0px 4px 8px 3px rgba(0, 0, 0, 0.04)"
10028
9809
  };
10029
9810
  var shadow_default = shadow;
9811
+ async function handleFormSubmission({
9812
+ id,
9813
+ createAction,
9814
+ updateAction,
9815
+ customAction,
9816
+ successMessages,
9817
+ onSuccess
9818
+ }) {
9819
+ let result = null;
9820
+ let message = null;
9821
+ if (customAction) {
9822
+ result = await customAction();
9823
+ message = successMessages?.custom || "";
9824
+ } else {
9825
+ if (id) {
9826
+ if (updateAction) {
9827
+ result = await updateAction();
9828
+ message = successMessages?.update || "";
9829
+ }
9830
+ } else {
9831
+ if (createAction) {
9832
+ result = await createAction();
9833
+ message = successMessages?.create || "";
9834
+ }
9835
+ }
9836
+ }
9837
+ if (result && typeof result === "object") {
9838
+ const errorData = result.props?.error || result.error;
9839
+ if (errorData) {
9840
+ if (errorData?.status === 422 && errorData?.errors) {
9841
+ Object.values(errorData.errors).forEach((errorMessages) => {
9842
+ if (Array.isArray(errorMessages)) {
9843
+ errorMessages.forEach((message2) => {
9844
+ if (message2.trim()) {
9845
+ toast.error(message2.trim());
9846
+ }
9847
+ });
9848
+ } else if (typeof errorMessages === "string") {
9849
+ toast.error(errorMessages);
9850
+ }
9851
+ });
9852
+ return null;
9853
+ }
9854
+ if (errorData?.message) {
9855
+ toast.error(errorData.message);
9856
+ return null;
9857
+ }
9858
+ }
9859
+ }
9860
+ if (message) {
9861
+ toast.success(message);
9862
+ }
9863
+ if (onSuccess) {
9864
+ onSuccess(result);
9865
+ }
9866
+ return result;
9867
+ }
10030
9868
  var useCopyToClipboard = (successMessage) => {
10031
9869
  const copyToClipboard = (initialText) => {
10032
9870
  const textArea = document.createElement("textarea");
@@ -10040,6 +9878,6 @@ var useCopyToClipboard = (successMessage) => {
10040
9878
  return { copyToClipboard };
10041
9879
  };
10042
9880
 
10043
- export { Alert, AlertDefault_default as AlertDefault, AlertError_default as AlertError, AlertGuard_default as AlertGuard, AlertInfo_default as AlertInfo, AlertWarning_default as AlertWarning, Api_default as Api, ArrowLeft_default as ArrowLeft, ArrowNarrowUpRight_default as ArrowNarrowUpRight, Avatar, BarChart, Boleto_default as Boleto, Box, Button, button_toggle_group_default as ButtonToggleGroup, CSV_default as CSV, Calendar_default as Calendar, Card_default as Card, CarrFree_default as CarrFree, CarretDown_default as CarretDown, CarretSingleRight_default as CarretSingleRight, CarrinhoAbandonado_default as CarrinhoAbandonado, Cart_default as Cart, Chargeback_default as Chargeback, Check_default as Check, Checkbox, checkbox_group_default as CheckboxGroup, Checkout_default as Checkout, ChevronDown_default as ChevronDown, ChevronLeftDouble_default as ChevronLeftDouble, CloseCheckbox_default as CloseCheckbox, CloseIcon_default as CloseIcon, Cloud_default as Cloud, CodeCircle_default as CodeCircle, Configuracoes_default as Configuracoes, Copy_default as Copy, CopyLink_default as CopyLink, Counter, CreditCard_default as CreditCard, Cupom_default as Cupom, CurrencyInput, CustomSelect, Dashboard_default as Dashboard, datapicker_default as DatePicker, DeleteModal, Delivery_default as Delivery, Depoimentos_default as Depoimentos, Distribuicao_default as Distribuicao, Distribution_default as Distribution, Dominios_default as Dominios, DownloadArrow_default as DownloadArrow, Drag_default as Drag, DropdownContext, DropdownItens, DropdownTrigger, DrowpdownButton, Edit_default as Edit, Emails_default as Emails, Extrato_default as Extrato, EyeInput_default as EyeInput, EyeOff_default as EyeOff, FeedbackBadge, FileMinus_default as FileMinus, FileUploadWithDisplayName as FileUpload, FilterDrawer, FilterLines_default as FilterLines, FilterList, FilterListContext, FilterTrigger, Financeiro_default as Financeiro, FormWrapper, Frete_default as Frete, FreteGratis_default as FreteGratis, GeneralPageLinks, Gestao_default as Gestao, Globe_default as Globe, GlobeVariant_default as GlobeVariant, Grid, GridColumn, Guard_default as Guard, Heading, Headphones_default as Headphones, Help_default as Help, HelpCircle_default as HelpCircle, Home_default as Home, InfoCircle_default as InfoCircle, Input, Integracoes_default as Integracoes, LineChart, Link4 as Link, Link_default as LinkIcon, LoadingSpinner_default as LoadingSpinner, Lock_default as Lock, LockInput_default as LockInput, Logistica_default as Logistica, Loja_default as Loja, LojaAlert_default as LojaAlert, LojaAlertSuccess_default as LojaAlertSuccess, Mail_default as Mail, MailInput_default as MailInput, MarkerPin_default as MarkerPin, Marketing_default as Marketing, MediumRisk_default as MediumRisk, Message_default as Message, Modal, Money_default as Money, MultiSelect, icones_default as NewIcons, NewMessage_default as NewMessage, NewNotification_default as NewNotification, Notificacoes_default as Notificacoes, Notification_default as Notification, NotificationItem, Notifications_default as Notifications, OrderBump_default as OrderBump, PageContainer, PaymentCard, PermissaoDeAcesso_default as PermissaoDeAcesso, PhoneCall_default as PhoneCall, PieChart, Pix_default as Pix, Pixels_default as Pixels, Planilha_default as Planilha, Plus_default as Plus, Prechargeback_default as Prechargeback, PrefetchLink, PreviewPhone, PriceSkeleton, Produto_default as Produto, Produtos_default as Produtos, Promocoes_default as Promocoes, RecuperacaoDeCarrinho_default as RecuperacaoDeCarrinho, Refresh_default as Refresh, Relatorios_default as Relatorios, RestricaoDeAcesso_default as RestricaoDeAcesso, Ribbon, Risco_default as Risco, Sac_default as Sac, SearchMd_default as SearchMd, SelectableOption, Separator, Signout_default as Signout, SliderInput, SlidingPanel, Spinner2 as Spinner, Spinner_default as SpinnerIcon, StatusBadge, Store_default as Store, Switch2 as Switch, Switch_default as SwitchIcon, Table, Tabs, Text, Textarea, TimeInput, TimerCounter, TimerCounterWithoutSeconds, Tooltip, Transfer_default as Transfer, Trash_default as Trash, Truck_default as Truck, Upsell_default as Upsell, User_default as User, Users_default as Users, VerticalPoints_default as VerticalPoints, Warning_default as Warning, Webhook_default2 as Webhook, Webhook_default as WebhookConfig, Whatsapp_default as Whatsapp, Xlsx_default as Xlsx, Yever_default as Yever, calculateCurrencyOperation, cn, colors_default as colors, font_family_default as fontFamily, formatCNPJ, formatCNPJCPF, formatCPF, formatCurrency, formatCurrencyShort, formatDate, formatDateAndReturnPassedHours, formatDateGeneric, formatDateInPassedDays, formatDateTime, formatDateToISO, formatIP, formatName, formatNumberToCurrency, formatPhone, formatPostalCode, formatRawDigitsToCurrency, formatTime as formatTimeWithSeconds, formatTime2 as formatTimeWithoutSeconds, getDates, handleFormSubmission, nextReplaceUrl, parseFormattedCurrency, parseParametersIntoUrl, searchParamsToUrl, shadow_default as shadow, transformDateToAmericanFormat, transformToCurrency, transformToNumber, transformToPercentage, truncateString, useCopyToClipboard, useFetchClientSide };
9881
+ export { Alert, AlertDefault_default as AlertDefault, AlertError_default as AlertError, AlertGuard_default as AlertGuard, AlertInfo_default as AlertInfo, AlertWarning_default as AlertWarning, Api_default as Api, ArrowLeft_default as ArrowLeft, ArrowNarrowUpRight_default as ArrowNarrowUpRight, Avatar, BarChart, Boleto_default as Boleto, Box, Button, button_toggle_group_default as ButtonToggleGroup, CSV_default as CSV, Calendar_default as Calendar, Card_default as Card, CarrFree_default as CarrFree, CarretDown_default as CarretDown, CarretSingleRight_default as CarretSingleRight, CarrinhoAbandonado_default as CarrinhoAbandonado, Cart_default as Cart, Chargeback_default as Chargeback, Check_default as Check, Checkbox, checkbox_group_default as CheckboxGroup, Checkout_default as Checkout, ChevronDown_default as ChevronDown, ChevronLeftDouble_default as ChevronLeftDouble, CloseCheckbox_default as CloseCheckbox, CloseIcon_default as CloseIcon, Cloud_default as Cloud, CodeCircle_default as CodeCircle, Configuracoes_default as Configuracoes, Copy_default as Copy, CopyLink_default as CopyLink, Counter, CreditCard_default as CreditCard, Cupom_default as Cupom, CurrencyInput, CustomSelect, Dashboard_default as Dashboard, datapicker_default as DatePicker, Delivery_default as Delivery, Depoimentos_default as Depoimentos, Distribuicao_default as Distribuicao, Distribution_default as Distribution, Dominios_default as Dominios, DownloadArrow_default as DownloadArrow, Drag_default as Drag, DropdownContext, DropdownItens, DropdownTrigger, DrowpdownButton, Edit_default as Edit, Emails_default as Emails, Extrato_default as Extrato, EyeInput_default as EyeInput, EyeOff_default as EyeOff, FeedbackBadge, FileMinus_default as FileMinus, FileUploadWithDisplayName as FileUpload, FilterDrawer, FilterLines_default as FilterLines, FilterList, FilterListContext, FilterTrigger, Financeiro_default as Financeiro, FormWrapper, Frete_default as Frete, FreteGratis_default as FreteGratis, GeneralPageLinks, Gestao_default as Gestao, Globe_default as Globe, GlobeVariant_default as GlobeVariant, Grid, GridColumn, Guard_default as Guard, Heading, Headphones_default as Headphones, Help_default as Help, HelpCircle_default as HelpCircle, Home_default as Home, InfoCircle_default as InfoCircle, Input, Integracoes_default as Integracoes, LineChart, Link4 as Link, Link_default as LinkIcon, LoadingSpinner_default as LoadingSpinner, Lock_default as Lock, LockInput_default as LockInput, Logistica_default as Logistica, Loja_default as Loja, LojaAlert_default as LojaAlert, LojaAlertSuccess_default as LojaAlertSuccess, Mail_default as Mail, MailInput_default as MailInput, MarkerPin_default as MarkerPin, Marketing_default as Marketing, MediumRisk_default as MediumRisk, Message_default as Message, Modal, Money_default as Money, MultiSelect, icones_default as NewIcons, NewMessage_default as NewMessage, NewNotification_default as NewNotification, Notificacoes_default as Notificacoes, Notification_default as Notification, NotificationItem, Notifications_default as Notifications, OrderBump_default as OrderBump, PageContainer, PaymentCard, PermissaoDeAcesso_default as PermissaoDeAcesso, PhoneCall_default as PhoneCall, PieChart, Pix_default as Pix, Pixels_default as Pixels, Planilha_default as Planilha, Plus_default as Plus, Prechargeback_default as Prechargeback, PrefetchLink, PreviewPhone, PriceSkeleton, Produto_default as Produto, Produtos_default as Produtos, Promocoes_default as Promocoes, RecuperacaoDeCarrinho_default as RecuperacaoDeCarrinho, Refresh_default as Refresh, Relatorios_default as Relatorios, RestricaoDeAcesso_default as RestricaoDeAcesso, Ribbon, Risco_default as Risco, Sac_default as Sac, SearchMd_default as SearchMd, SelectableOption, Separator, Signout_default as Signout, SliderInput, SlidingPanel, Spinner2 as Spinner, Spinner_default as SpinnerIcon, StatusBadge, Store_default as Store, Switch2 as Switch, Switch_default as SwitchIcon, Table, Tabs, Text, Textarea, TimeInput, TimerCounter, TimerCounterWithoutSeconds, Tooltip, Transfer_default as Transfer, Trash_default as Trash, Truck_default as Truck, Upsell_default as Upsell, User_default as User, Users_default as Users, VerticalPoints_default as VerticalPoints, Warning_default as Warning, Webhook_default2 as Webhook, Webhook_default as WebhookConfig, Whatsapp_default as Whatsapp, Xlsx_default as Xlsx, Yever_default as Yever, calculateCurrencyOperation, cn, colors_default as colors, font_family_default as fontFamily, formatCNPJ, formatCNPJCPF, formatCPF, formatCurrency, formatCurrencyShort, formatDate, formatDateAndReturnPassedHours, formatDateGeneric, formatDateInPassedDays, formatDateTime, formatDateToISO, formatIP, formatName, formatNumberToCurrency, formatPhone, formatPostalCode, formatRawDigitsToCurrency, formatTime as formatTimeWithSeconds, formatTime2 as formatTimeWithoutSeconds, getDates, handleFormSubmission, nextReplaceUrl, parseFormattedCurrency, parseParametersIntoUrl, searchParamsToUrl, shadow_default as shadow, transformDateToAmericanFormat, transformToCurrency, transformToNumber, transformToPercentage, truncateString, useCopyToClipboard, useFetchClientSide };
10044
9882
  //# sourceMappingURL=index.mjs.map
10045
9883
  //# sourceMappingURL=index.mjs.map