@yeverlibs/ds 1.1.13 → 1.1.14

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,24 +2,22 @@ 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
23
  // src/lib/utils.ts
@@ -3405,7 +3403,7 @@ var Avatar = ({ name, src, size = "large", className }) => {
3405
3403
  size === "xlarge" && "h-[44px] min-w-[44px]",
3406
3404
  className
3407
3405
  ),
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) }) })
3406
+ 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
3407
  }
3410
3408
  );
3411
3409
  };
@@ -3930,603 +3928,142 @@ var CheckboxGroup = ({
3930
3928
  ] });
3931
3929
  };
3932
3930
  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);
3931
+ var DropdownContext = createContext({
3932
+ isOpen: false,
3933
+ toggleDropdown: () => void 0,
3934
+ closeDropdown: () => void 0
3935
+ });
3936
+ var DropdownContainer = ({ children, ...props }) => {
3937
+ return /* @__PURE__ */ jsx(Box, { className: "relative", ...props, children });
3938
+ };
3939
+ var ButtonAction = ({ children, ...props }) => {
3940
+ const context = useContext(DropdownContext);
3941
+ if (!context) {
3942
+ throw new Error("Button must be used within a ButtonTrigger");
3943
+ }
3944
+ const { toggleDropdown } = context;
3945
+ return /* @__PURE__ */ jsx(
3946
+ Button,
3947
+ {
3948
+ $variant: "tertiary",
3949
+ className: "hover:bg-transparent min-h-8 min-w-8 border-none p-0",
3950
+ onClick: toggleDropdown,
3951
+ ...props,
3952
+ children
3946
3953
  }
3947
- }, [isOpen]);
3954
+ );
3955
+ };
3956
+ var DropdownContent = ({ children, ...props }) => {
3957
+ const { className } = props;
3958
+ return /* @__PURE__ */ jsx(Box, { ...props, className: cn("absolute right-0 overflow-x-hidden !p-0", className), children });
3959
+ };
3960
+ var DropdownContentHeader = ({ children, ...props }) => {
3961
+ const { className } = props;
3962
+ return /* @__PURE__ */ jsx("div", { ...props, className: cn("border-b border-gray-300", className), children });
3963
+ };
3964
+ var DropdownContentFooter = ({ children, ...props }) => {
3965
+ return /* @__PURE__ */ jsx("div", { ...props, children });
3966
+ };
3967
+ var DropdownTrigger = ({ children, ...props }) => {
3968
+ const [isOpen, setIsOpen] = useState(false);
3969
+ const containerRef = useRef(null);
3970
+ const toggleDropdown = () => {
3971
+ setIsOpen((prev) => !prev);
3972
+ };
3973
+ const closeDropdown = () => {
3974
+ setIsOpen(false);
3975
+ };
3948
3976
  useEffect(() => {
3949
- const handleEsc = (event) => {
3950
- if (event.key === "Escape") {
3951
- onClose();
3977
+ const handleClickOutside = (event) => {
3978
+ if (containerRef.current && !containerRef.current.contains(event.target)) {
3979
+ closeDropdown();
3952
3980
  }
3953
3981
  };
3954
- window.addEventListener("keydown", handleEsc);
3982
+ document.addEventListener("mousedown", handleClickOutside);
3955
3983
  return () => {
3956
- window.removeEventListener("keydown", handleEsc);
3984
+ document.removeEventListener("mousedown", handleClickOutside);
3957
3985
  };
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
- );
3986
+ }, [containerRef]);
3987
+ return /* @__PURE__ */ jsx(DropdownContext.Provider, { value: { isOpen, toggleDropdown, closeDropdown }, children: /* @__PURE__ */ jsx("div", { ref: containerRef, className: "relative w-full", ...props, children }) });
3992
3988
  };
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,
3989
+ var DrowpdownButton = {
3990
+ Container: DropdownContainer,
3991
+ Button: ButtonAction,
3992
+ Content: DropdownContent,
3993
+ Header: DropdownContentHeader,
3994
+ Footer: DropdownContentFooter
3995
+ };
3996
+ var DropdownItens = ({ items }) => {
3997
+ return /* @__PURE__ */ jsx(Box, { className: "flex w-full min-w-[230px] flex-col justify-end p-0 shadow-base", children: items.map((item, index) => {
3998
+ const isFirst = index === 0;
3999
+ const isLast = index === items.length - 1;
4000
+ const borderRadiusClass = isFirst ? "rounded-t-md" : isLast ? "rounded-b-md" : "!rounded-none";
4001
+ return React107__default.cloneElement(item, {
4002
+ className: `${item.props.className} ${borderRadiusClass} border-b border-gray-200`,
4003
+ key: index
4004
+ });
4005
+ }) });
4006
+ };
4007
+ var FeedbackBadge = ({
4008
+ children,
4009
+ $variant,
4010
+ customClassName,
4011
+ tagColor,
4012
+ tagTextColor,
4013
+ ...props
4014
+ }) => {
4015
+ const { onClick } = props;
4016
+ const inlineStyles = {
4017
+ backgroundColor: tagColor,
4018
+ color: tagTextColor,
4019
+ borderColor: tagColor
4020
+ };
4021
+ return /* @__PURE__ */ jsx(
4022
+ "div",
3997
4023
  {
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, {})
4024
+ className: cn(
4025
+ "flex w-fit items-center justify-center rounded border px-2 py-1 text-xs font-medium",
4026
+ onClick && "cursor-pointer",
4027
+ customClassName,
4028
+ {
4029
+ "border-green-100 bg-green-0 text-green-800": $variant === "success",
4030
+ "border-orange-100 bg-orange-0 text-orange-800": $variant === "warning",
4031
+ "border-yellow-600 bg-orange-0 text-orange-100": $variant === "risk",
4032
+ "border-red-100 bg-red-0 text-red-800": $variant === "error",
4033
+ "border-gray-300 bg-gray-0 text-black": $variant === "default",
4034
+ "cursor-pointer border-orange-1000 bg-orange-1000 font-bold text-white": $variant === "ribbon"
4035
+ }
4036
+ ),
4037
+ onClick,
4038
+ style: inlineStyles,
4039
+ ...props,
4040
+ children
4003
4041
  }
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: ""
4042
+ );
4023
4043
  };
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
- ] });
4044
+ var FilterListContext = createContext({
4045
+ isOpen: false,
4046
+ toggleDropdown: () => void 0,
4047
+ closeDropdown: () => void 0
4048
+ });
4049
+ var FilterContainer = ({ children }) => {
4050
+ return /* @__PURE__ */ jsx(Box, { className: "w-full p-0", children });
4029
4051
  };
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"
4052
+ var FilterHeader = ({ children }) => {
4053
+ 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
4054
  };
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 });
4055
+ var FilterContent = ({ children }) => {
4056
+ 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
4057
  };
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
4058
+ var FilterFooter = ({ children, className }) => {
4059
+ return /* @__PURE__ */ jsx(
4060
+ "div",
4061
+ {
4062
+ className: cn(
4063
+ "flex flex-col justify-between gap-3 rounded-b-lg border-t border-gray-300 bg-gray-0 p-4 px-6",
4064
+ className
4065
+ ),
4066
+ children
4530
4067
  }
4531
4068
  );
4532
4069
  };
@@ -5507,6 +5044,38 @@ var SlidingPanel = {
5507
5044
  Footer: SlidingPanelFooter
5508
5045
  };
5509
5046
 
5047
+ // src/_design-system/typography/heading/styles.ts
5048
+ var headingStyles = {
5049
+ h1: "text-2xl font-semibold text-black",
5050
+ h2: "text-lg font-semibold text-black",
5051
+ h3: "text-lg font-semibold text-black",
5052
+ h4: "text-base font-semibold text-black",
5053
+ h5: "text-sm font-semibold text-black",
5054
+ h6: ""
5055
+ };
5056
+ var Heading = ({ $as: Tag, children, className = "", tooltip }) => {
5057
+ return /* @__PURE__ */ jsxs(Tag, { className: cn(headingStyles[Tag], className, tooltip ? "flex items-center gap-2" : ""), children: [
5058
+ children,
5059
+ tooltip ? /* @__PURE__ */ jsx(Tooltip, { text: tooltip }) : null
5060
+ ] });
5061
+ };
5062
+
5063
+ // src/_design-system/typography/text/styles.ts
5064
+ var textStyles = {
5065
+ p: "text-base font-normal text-gray-600",
5066
+ span: "text-sm font-medium text-gray-600",
5067
+ div: "",
5068
+ small: "text-sm font-normal text-gray-600",
5069
+ label: "text-sm font-medium text-gray-600"
5070
+ };
5071
+ var Text = ({ $as: Tag, children, className = "", ...props }) => {
5072
+ const elementProps = {
5073
+ className: cn(textStyles[Tag], className),
5074
+ ...props
5075
+ };
5076
+ return /* @__PURE__ */ jsx(Tag, { ...elementProps, children });
5077
+ };
5078
+
5510
5079
  // src/utils/next-replace-url/index.ts
5511
5080
  var nextReplaceUrl = (key, value, pathname) => {
5512
5081
  const params = new URLSearchParams(window.location.search);
@@ -6083,6 +5652,87 @@ var Link4 = ({
6083
5652
  }
6084
5653
  );
6085
5654
  };
5655
+ var ModalContainer = ({ isOpen, onClose, className, children }) => {
5656
+ const [isVisible, setIsVisible] = useState(false);
5657
+ const [isMounted, setIsMounted] = useState(false);
5658
+ useEffect(() => {
5659
+ setIsMounted(true);
5660
+ }, []);
5661
+ useEffect(() => {
5662
+ if (isOpen) {
5663
+ document.documentElement.classList.add("no-scroll-modal");
5664
+ setIsVisible(true);
5665
+ } else {
5666
+ document.documentElement.classList.remove("no-scroll-modal");
5667
+ setIsVisible(false);
5668
+ }
5669
+ }, [isOpen]);
5670
+ useEffect(() => {
5671
+ const handleEsc = (event) => {
5672
+ if (event.key === "Escape") {
5673
+ onClose();
5674
+ }
5675
+ };
5676
+ window.addEventListener("keydown", handleEsc);
5677
+ return () => {
5678
+ window.removeEventListener("keydown", handleEsc);
5679
+ };
5680
+ }, [onClose]);
5681
+ if (!isMounted) return null;
5682
+ const portalContainer = document.getElementById("portal-root");
5683
+ if (!portalContainer) return null;
5684
+ return ReactDOM.createPortal(
5685
+ /* @__PURE__ */ jsxs(
5686
+ "div",
5687
+ {
5688
+ className: cn(
5689
+ "fixed inset-0 z-[60] flex items-center justify-center",
5690
+ isOpen ? "opacity-100" : "opacity-0",
5691
+ isVisible ? "pointer-events-auto" : "pointer-events-none",
5692
+ "transition-opacity duration-300 md:mx-auto",
5693
+ className
5694
+ ),
5695
+ children: [
5696
+ /* @__PURE__ */ jsx("div", { className: "fixed inset-0 bg-black bg-opacity-50", onClick: onClose }),
5697
+ /* @__PURE__ */ jsx(
5698
+ "div",
5699
+ {
5700
+ className: cn(
5701
+ "shadow-lg z-10 w-full transform overflow-hidden rounded-lg bg-white transition-transform duration-300",
5702
+ isOpen ? "scale-100" : "scale-95",
5703
+ className ? className : "max-w-lg"
5704
+ ),
5705
+ style: { margin: "1rem" },
5706
+ children
5707
+ }
5708
+ )
5709
+ ]
5710
+ }
5711
+ ),
5712
+ portalContainer
5713
+ );
5714
+ };
5715
+ 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: [
5716
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between gap-3", children }),
5717
+ /* @__PURE__ */ jsx(
5718
+ Button,
5719
+ {
5720
+ onClick: onClose,
5721
+ $variant: "tertiary",
5722
+ className: "absolute right-4 top-4 w-auto border-none p-0",
5723
+ type: "button",
5724
+ children: /* @__PURE__ */ jsx(CloseIcon_default, {})
5725
+ }
5726
+ )
5727
+ ] });
5728
+ var ModalContent = ({ children, className = "" }) => /* @__PURE__ */ jsx("div", { className: cn("px-8 py-6", className), children });
5729
+ var ModalFooter = ({ children, className = "" }) => /* @__PURE__ */ jsx("div", { className: cn("flex border-t border-gray-300 px-6 py-4", className), children });
5730
+ var Modal = {
5731
+ Container: ModalContainer,
5732
+ Header: ModalHeader,
5733
+ Content: ModalContent,
5734
+ Footer: ModalFooter
5735
+ };
6086
5736
 
6087
5737
  // src/_design-system/helpers/formatDateAndReturnPassedHours.ts
6088
5738
  var formatDateAndReturnPassedHours = (date) => {
@@ -6093,7 +5743,7 @@ var formatDateAndReturnPassedHours = (date) => {
6093
5743
  var NotificationItem = ({ user, message, date }) => {
6094
5744
  return /* @__PURE__ */ jsxs("div", { className: "flex cursor-pointer items-start gap-4 px-6 py-4 hover:bg-gray-0", children: [
6095
5745
  /* @__PURE__ */ jsx(
6096
- Image4,
5746
+ Image3,
6097
5747
  {
6098
5748
  src: "/images/yever-notification-avatar.svg",
6099
5749
  width: 49,
@@ -6152,7 +5802,7 @@ var PaymentCard = ({
6152
5802
  /* @__PURE__ */ jsx("span", { className: "font-semibold text-black", children: paymentDate })
6153
5803
  ] })
6154
5804
  ] }),
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 }) })
5805
+ /* @__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
5806
  ] });
6157
5807
  };
6158
5808
  var PreviewPhone = ({ children, cartPosition = "bottom", bodyColor }) => {
@@ -6709,7 +6359,7 @@ var TableContent = ({
6709
6359
  rowIndex
6710
6360
  )) : /* @__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
6361
  /* @__PURE__ */ jsx(
6712
- Image4,
6362
+ Image3,
6713
6363
  {
6714
6364
  src: "/empty-table.svg",
6715
6365
  width: 666,
@@ -6783,15 +6433,15 @@ var TableContent = ({
6783
6433
  var Table = (props) => {
6784
6434
  return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(TableContent, { ...props }) });
6785
6435
  };
6786
- var Tabs = ({ headers: headers2, children, noGap, active, alignDiv = "full" }) => {
6436
+ var Tabs = ({ headers, children, noGap, active, alignDiv = "full" }) => {
6787
6437
  const [activeTab, setActiveTab] = useState(active || 0);
6788
- const flattenHeaders = (headers3) => {
6789
- if (Array.isArray(headers3[0])) {
6790
- return headers3.flat();
6438
+ const flattenHeaders = (headers2) => {
6439
+ if (Array.isArray(headers2[0])) {
6440
+ return headers2.flat();
6791
6441
  }
6792
- return headers3;
6442
+ return headers2;
6793
6443
  };
6794
- const flattenedHeaders = flattenHeaders(headers2);
6444
+ const flattenedHeaders = flattenHeaders(headers);
6795
6445
  return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col", noGap ? "" : "gap-4"), children: [
6796
6446
  /* @__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
6447
  "button",
@@ -7174,7 +6824,7 @@ var MultiSelect = ({
7174
6824
  onSelect(newValue);
7175
6825
  };
7176
6826
  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 }) }),
6827
+ 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
6828
  /* @__PURE__ */ jsx("span", { className: "text-sm", children: option.label })
7179
6829
  ] });
7180
6830
  return /* @__PURE__ */ jsxs("div", { className: cn("relative w-full", className), children: [
@@ -7262,7 +6912,7 @@ var CustomSelect = ({
7262
6912
  onSelect(option);
7263
6913
  };
7264
6914
  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 }) }),
6915
+ 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
6916
  /* @__PURE__ */ jsx("span", { className: "text-sm", children: option.label })
7267
6917
  ] });
7268
6918
  return /* @__PURE__ */ jsxs("div", { className: cn("relative w-full", className), children: [
@@ -8072,7 +7722,7 @@ function FileUploadComponent({
8072
7722
  }
8073
7723
  ) : /* @__PURE__ */ jsx("div", { className: "relative flex h-full w-full items-center justify-center", children: filePreview && isImagePreview(filePreview) ? /* @__PURE__ */ jsxs(Fragment, { children: [
8074
7724
  /* @__PURE__ */ jsx("label", { htmlFor: `${name}-input`, className: "block h-full w-full cursor-pointer", children: /* @__PURE__ */ jsx(
8075
- Image4,
7725
+ Image3,
8076
7726
  {
8077
7727
  src: filePreview,
8078
7728
  alt: "Preview",
@@ -8099,7 +7749,7 @@ function FileUploadComponent({
8099
7749
  ] }) : /* @__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
7750
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
8101
7751
  /* @__PURE__ */ jsx(
8102
- Image4,
7752
+ Image3,
8103
7753
  {
8104
7754
  src: isPdfFile ? "/icons/pdf.png" : "/icons/xlsx.png",
8105
7755
  alt: "Preview",
@@ -8312,6 +7962,138 @@ var PieChart = ({
8312
7962
  }
8313
7963
  );
8314
7964
  };
7965
+ async function getCsrfToken() {
7966
+ const baseURL = process.env.NEXT_PUBLIC_API_URL ?? "http://api.yever.local";
7967
+ const response = await fetch(`${baseURL}/sanctum/csrf-cookie`, {
7968
+ credentials: "include",
7969
+ headers: {
7970
+ "X-Requested-With": "XMLHttpRequest"
7971
+ }
7972
+ });
7973
+ if (!response.ok) {
7974
+ throw new Error("Falha ao obter token CSRF");
7975
+ }
7976
+ await new Promise((resolve) => setTimeout(resolve, 100));
7977
+ }
7978
+ async function apiFetch(options) {
7979
+ const baseURL = process.env.NEXT_PUBLIC_API_URL ?? "";
7980
+ const isAbsolute = /^https?:\/\//i.test(options.url);
7981
+ const url = isAbsolute ? options.url : `${baseURL}${options.url}`;
7982
+ const method = (options.method ?? "GET").toString().toLowerCase();
7983
+ const needsCSRFToken = ["post", "put", "delete"].includes(method);
7984
+ const hasCSRFCookie = Cookies.get("XSRF-TOKEN");
7985
+ if (needsCSRFToken && !hasCSRFCookie) {
7986
+ await getCsrfToken();
7987
+ }
7988
+ const defaultHeaders = {
7989
+ "X-Requested-With": "XMLHttpRequest",
7990
+ Accept: "application/json"
7991
+ };
7992
+ if (!(options.body instanceof FormData)) {
7993
+ defaultHeaders["Content-Type"] = "application/json";
7994
+ }
7995
+ const finalHeaders = new Headers(defaultHeaders);
7996
+ if (options.headers) {
7997
+ if (options.headers instanceof Headers) {
7998
+ options.headers.forEach((v, k) => finalHeaders.set(k, v));
7999
+ } else {
8000
+ Object.entries(options.headers).forEach(([k, v]) => {
8001
+ if (v !== void 0) finalHeaders.set(k, v);
8002
+ });
8003
+ }
8004
+ }
8005
+ const csrfToken = Cookies.get("XSRF-TOKEN");
8006
+ if (csrfToken) {
8007
+ finalHeaders.set("X-XSRF-TOKEN", csrfToken);
8008
+ }
8009
+ let finalOptions = options;
8010
+ if (options.body) {
8011
+ finalOptions = {
8012
+ ...options,
8013
+ body: options.body instanceof FormData ? options.body : JSON.stringify(options.body)
8014
+ };
8015
+ }
8016
+ let response = await fetch(url, {
8017
+ credentials: "include",
8018
+ headers: finalHeaders,
8019
+ ...finalOptions
8020
+ });
8021
+ if (response.status === 419) {
8022
+ Cookies.remove("XSRF-TOKEN");
8023
+ await getCsrfToken();
8024
+ const newToken = Cookies.get("XSRF-TOKEN");
8025
+ if (newToken) {
8026
+ finalHeaders.set("X-XSRF-TOKEN", newToken);
8027
+ }
8028
+ response = await fetch(url, {
8029
+ credentials: "include",
8030
+ headers: finalHeaders,
8031
+ ...options
8032
+ });
8033
+ if (!response.ok) {
8034
+ Cookies.remove("XSRF-TOKEN");
8035
+ Cookies.remove("yeverClientUser");
8036
+ window.location.href = "/login";
8037
+ return Promise.reject(new Error("CSRF token expirado"));
8038
+ }
8039
+ }
8040
+ const headers = {};
8041
+ response.headers.forEach((value, key) => {
8042
+ headers[key] = value;
8043
+ });
8044
+ if (!response.ok) {
8045
+ const data2 = await response.json().catch(() => null);
8046
+ const errorMessage = typeof data2 === "object" && data2 !== null && "message" in data2 ? data2.message : "Request failed";
8047
+ const error = new Error(errorMessage);
8048
+ error.status = response.status;
8049
+ error.response = {
8050
+ data: data2,
8051
+ status: response.status
8052
+ };
8053
+ throw error;
8054
+ }
8055
+ let data = null;
8056
+ if (options.responseType === "blob") {
8057
+ data = await response.blob().catch(() => null);
8058
+ } else {
8059
+ data = await response.json().catch(() => null);
8060
+ }
8061
+ return {
8062
+ status: response.status,
8063
+ statusText: response.statusText,
8064
+ data,
8065
+ headers
8066
+ };
8067
+ }
8068
+
8069
+ // src/utils/parse-parameters-into-url/index.tsx
8070
+ var parseParametersIntoUrl = (url, query, filtersAllowed) => {
8071
+ let urlFiltered = url;
8072
+ for (const key in query) {
8073
+ if (query && Object.keys(query).length > 0) {
8074
+ urlFiltered = urlFiltered.replace(`/${key}/`, `/${query[key]}/`);
8075
+ urlFiltered = urlFiltered.replace(`/${key}`, `/${query[key]}`);
8076
+ if (filtersAllowed && filtersAllowed.includes(key)) {
8077
+ if (urlFiltered.includes("?")) {
8078
+ if (key === "searchNew") {
8079
+ urlFiltered = urlFiltered + `&${key}=${atob(query[key])}`;
8080
+ } else {
8081
+ urlFiltered = urlFiltered + `&${key}=${query[key]}`;
8082
+ }
8083
+ } else {
8084
+ if (key === "searchNew") {
8085
+ urlFiltered = urlFiltered + `?${key}=${atob(query[key])}`;
8086
+ } else {
8087
+ urlFiltered = urlFiltered + `?${key}=${query[key]}`;
8088
+ }
8089
+ }
8090
+ }
8091
+ }
8092
+ }
8093
+ return urlFiltered;
8094
+ };
8095
+
8096
+ // src/hooks/use-fetch-client-side/index.tsx
8315
8097
  var noopLoading = {
8316
8098
  loadingActions: {
8317
8099
  setLoading: () => {
@@ -8372,22 +8154,22 @@ function useFetchClientSide({
8372
8154
  if (body instanceof FormData) {
8373
8155
  delete configHeaders["Content-Type"];
8374
8156
  }
8375
- const headers2 = {
8157
+ const headers = {
8376
8158
  "X-Requested-With": "XMLHttpRequest",
8377
8159
  Accept: "application/json",
8378
8160
  ...configHeaders
8379
8161
  };
8380
8162
  if (body && !(body instanceof FormData)) {
8381
- headers2["Content-Type"] = "application/json";
8163
+ headers["Content-Type"] = "application/json";
8382
8164
  }
8383
8165
  if (csrfToken) {
8384
- headers2["X-XSRF-TOKEN"] = decodeURIComponent(csrfToken);
8166
+ headers["X-XSRF-TOKEN"] = decodeURIComponent(csrfToken);
8385
8167
  }
8386
8168
  const response = await apiFetch({
8387
8169
  url: customUrl || urlFiltered,
8388
8170
  method: customMethod || method,
8389
8171
  body,
8390
- headers: headers2,
8172
+ headers,
8391
8173
  credentials: "include",
8392
8174
  signal,
8393
8175
  responseType: config?.responseType
@@ -10027,6 +9809,63 @@ var shadow = {
10027
9809
  store: "0px 4px 8px 3px rgba(0, 0, 0, 0.04)"
10028
9810
  };
10029
9811
  var shadow_default = shadow;
9812
+ async function handleFormSubmission({
9813
+ id,
9814
+ createAction,
9815
+ updateAction,
9816
+ customAction,
9817
+ successMessages,
9818
+ onSuccess
9819
+ }) {
9820
+ let result = null;
9821
+ let message = null;
9822
+ if (customAction) {
9823
+ result = await customAction();
9824
+ message = successMessages?.custom || "";
9825
+ } else {
9826
+ if (id) {
9827
+ if (updateAction) {
9828
+ result = await updateAction();
9829
+ message = successMessages?.update || "";
9830
+ }
9831
+ } else {
9832
+ if (createAction) {
9833
+ result = await createAction();
9834
+ message = successMessages?.create || "";
9835
+ }
9836
+ }
9837
+ }
9838
+ if (result && typeof result === "object") {
9839
+ const errorData = result.props?.error || result.error;
9840
+ if (errorData) {
9841
+ if (errorData?.status === 422 && errorData?.errors) {
9842
+ Object.values(errorData.errors).forEach((errorMessages) => {
9843
+ if (Array.isArray(errorMessages)) {
9844
+ errorMessages.forEach((message2) => {
9845
+ if (message2.trim()) {
9846
+ toast.error(message2.trim());
9847
+ }
9848
+ });
9849
+ } else if (typeof errorMessages === "string") {
9850
+ toast.error(errorMessages);
9851
+ }
9852
+ });
9853
+ return null;
9854
+ }
9855
+ if (errorData?.message) {
9856
+ toast.error(errorData.message);
9857
+ return null;
9858
+ }
9859
+ }
9860
+ }
9861
+ if (message) {
9862
+ toast.success(message);
9863
+ }
9864
+ if (onSuccess) {
9865
+ onSuccess(result);
9866
+ }
9867
+ return result;
9868
+ }
10030
9869
  var useCopyToClipboard = (successMessage) => {
10031
9870
  const copyToClipboard = (initialText) => {
10032
9871
  const textArea = document.createElement("textarea");
@@ -10040,6 +9879,6 @@ var useCopyToClipboard = (successMessage) => {
10040
9879
  return { copyToClipboard };
10041
9880
  };
10042
9881
 
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 };
9882
+ 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
9883
  //# sourceMappingURL=index.mjs.map
10045
9884
  //# sourceMappingURL=index.mjs.map