@granto-umbrella/umbrella-components 3.0.29 → 3.0.30

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@granto-umbrella/umbrella-components",
3
- "version": "3.0.29",
3
+ "version": "3.0.30",
4
4
  "description": "Umbrella Components for React",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -36,8 +36,10 @@
36
36
  "@radix-ui/react-label": "^2.1.3",
37
37
  "@radix-ui/react-popover": "^1.1.11",
38
38
  "@radix-ui/react-radio-group": "^1.2.4",
39
+ "cpf-cnpj-validator": "^1.0.3",
39
40
  "date-fns": "^4.1.0",
40
41
  "lucide-react": "^0.488.0",
42
+ "make-mask": "^1.0.3",
41
43
  "phosphor-react": "^1.4.1",
42
44
  "radix": "^0.0.0",
43
45
  "react": "^18.3.1",
@@ -76,7 +78,6 @@
76
78
  "jest": "^29.7.0",
77
79
  "jest-environment-jsdom": "^29.7.0",
78
80
  "react-icons": "^5.4.0",
79
- "storybook": "8.4.7",
80
81
  "styled-components": "^6.1.19",
81
82
  "ts-jest": "^29.2.5",
82
83
  "typescript": "~5.6.2",
@@ -1,40 +1,45 @@
1
- import React from 'react';
2
-
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { cnpj } from 'cpf-cnpj-validator';
3
+ import { format, parseISO } from 'date-fns';
3
4
  import {
4
- FileText,
5
- CreditCard,
6
- Download,
7
- PlusCircle,
8
5
  ChevronDown,
9
6
  ChevronUp,
7
+ CreditCard,
8
+ Download,
9
+ FileText,
10
10
  Loader2,
11
+ PlusCircle,
11
12
  } from 'lucide-react';
13
+ import mask from 'make-mask';
14
+ import { ArrowCircleUpRight, Cube, FlowArrow, XCircle } from 'phosphor-react';
15
+ import React, { useState } from 'react';
16
+ import { useNavigate } from 'react-router-dom';
17
+
18
+ import Pill from '../../atoms/Pill/Pill';
19
+ import { mapRemoteToTimeline } from '../../molecules/TimeLine/TimeLine.mapper';
20
+ import { TimelineModal } from '../../organisms/TimelineModal/TimelineModal';
21
+ import { ExcludeModal } from '../ExcludeModal';
22
+ import { RefuseModal } from '../RefuseModal';
12
23
  import {
24
+ ActionButton,
25
+ Actions,
26
+ BodyRow,
13
27
  CardContainer,
28
+ DropdownMenu,
29
+ DropdownWrapper,
14
30
  HeaderRow,
15
- InfoRow,
16
31
  InfoLabel,
32
+ InfoRow,
33
+ InfoSubValue,
17
34
  InfoValue,
18
- Actions,
19
- DropdownWrapper,
20
- DropdownMenu,
21
35
  MenuItemProps,
36
+ ProcessValue,
37
+ ProdValue,
22
38
  StyledMenuItem,
23
39
  Text,
24
- BodyRow,
25
- InfoSubValue,
26
40
  TruncatedValue,
27
- ProdValue,
28
- ProcessValue,
29
- ActionButton,
30
41
  } from './InsuranceCard.styles';
31
- import { ArrowCircleUpRight, Cube, XCircle, FlowArrow } from 'phosphor-react';
32
- import { ExcludeModal } from '../ExcludeModal';
33
-
34
42
  import { InsuranceCardProps, StatusVariant } from './InsuranceCard.types';
35
- import { RefuseModal } from '../RefuseModal';
36
- import Pill from '../../atoms/Pill/Pill';
37
- import { TimelineModal } from '../../organisms/TimelineModal/TimelineModal';
38
43
 
39
44
  export const InsuranceCard: React.FC<InsuranceCardProps> = ({
40
45
  idGranto,
@@ -47,41 +52,118 @@ export const InsuranceCard: React.FC<InsuranceCardProps> = ({
47
52
  statusVariant,
48
53
  seguradoName,
49
54
  seguradoCnpj,
55
+ product,
50
56
  issuedDate,
51
57
  totalValue,
52
58
  processId,
53
59
  activeIndex,
54
60
  testId,
55
61
  openCardId,
56
- loadingItem,
57
- showRefuseModal,
58
- setShowRefuseModal,
59
- showExcludeModal,
60
- setShowExcludeModal,
61
- showTimeline,
62
- setShowTimeline,
63
- timelineItems,
64
- isTimelineLoading,
65
- fetchTimeline,
66
- showTimelineToggle,
67
- toggleOpen,
68
- handleClick,
69
- isAllowedByRoles,
70
- productTitle,
71
- productDescription,
72
- downloadFile,
73
- searchCerts,
74
- onEndorsementClick,
75
- irParaContinuarEmissao,
76
- abrirModalExcluirProposta,
77
- fecharModalExclusao,
78
- confirmarExclusao,
79
- abrirModalRecusarProposta,
80
- fecharModalRecusa,
81
- confirmarRecusa,
62
+ setOpenCardId,
63
+ runQuery,
64
+ useDownloadAndSupport,
65
+ useDownloadFile,
66
+ useChangeOrderStageAsync,
67
+ useMyStore,
68
+ useQueryClient,
69
+ useGetTimeline,
70
+ useAuthStoreV2,
82
71
  }) => {
72
+ const navigate = useNavigate();
73
+ const [loadingItem, setLoadingItem] = useState<string | null>(null);
74
+ const [showRefuseModal, setShowRefuseModal] = useState(false);
75
+ const [showExcludeModal, setShowExcludeModal] = useState(false);
76
+ const [showTimeline, setShowTimeline] = useState(false);
77
+ const [timelineItems, setTimelineItems] = useState<
78
+ ReturnType<typeof mapRemoteToTimeline>
79
+ >([]);
80
+ const { isLoading: isTimelineLoading, refetch: fetchTimeline } =
81
+ useGetTimeline({ orderId: idOrder, insuranceId: idInsurance });
82
+
83
+ const showTimelineToggle = async () => {
84
+ const willOpen = !showTimeline;
85
+
86
+ if (willOpen && (!timelineItems || timelineItems.length === 0)) {
87
+ setLoadingItem('linha_do_tempo');
88
+ setShowTimeline(true);
89
+ try {
90
+ const { data: remote } = await fetchTimeline();
91
+ setTimelineItems(mapRemoteToTimeline(remote ?? []));
92
+ } catch (err) {
93
+ console.error('Falha ao carregar timeline', err);
94
+ } finally {
95
+ setLoadingItem(null);
96
+ }
97
+ return;
98
+ }
99
+
100
+ setShowTimeline(willOpen);
101
+ };
102
+
83
103
  const isOpen = openCardId === idOrder;
84
104
 
105
+ const toggleOpen = () => {
106
+ setOpenCardId(isOpen ? null : idOrder);
107
+ };
108
+
109
+ const handleClick = async (
110
+ key: string,
111
+ callback: () => Promise<void> | void
112
+ ) => {
113
+ setLoadingItem(key);
114
+ await Promise.resolve(callback());
115
+ setLoadingItem(null);
116
+ };
117
+
118
+ const { isAllowedByRoles } = useAuthStoreV2();
119
+
120
+ const [productTitle, productDescription] = product;
121
+
122
+ const { downloadFile, searchCerts } = useDownloadFile(idOrder);
123
+ const { onEndorsementClick } = useDownloadAndSupport();
124
+ const mutateStageOrder = useChangeOrderStageAsync();
125
+ const { setData } = useMyStore();
126
+ const queryClient = useQueryClient();
127
+
128
+ const irParaContinuarEmissao = () => {
129
+ const stateData = idInsurance
130
+ ? { idInsurance, isSupply }
131
+ : { idOrder, isSupply };
132
+ if (
133
+ statusLabel === 'Proposta recusada' ||
134
+ statusLabel === 'Proposta excluída'
135
+ ) {
136
+ mutateStageOrder.mutateAsync(
137
+ {
138
+ id: idGranto,
139
+ newStage: 'IDLE',
140
+ },
141
+ {
142
+ onSuccess: () => {
143
+ queryClient.invalidateQueries({ queryKey: ['orders'] });
144
+ },
145
+ }
146
+ );
147
+ }
148
+ navigate('/issue', { state: stateData });
149
+
150
+ setData({});
151
+ };
152
+ const abrirModalExcluirProposta = () => setShowExcludeModal(true);
153
+ const fecharModalExclusao = () => setShowExcludeModal(false);
154
+
155
+ const confirmarExclusao = () => {
156
+ runQuery();
157
+ fecharModalExclusao();
158
+ };
159
+ const abrirModalRecusarProposta = () => setShowRefuseModal(true);
160
+ const fecharModalRecusa = () => setShowRefuseModal(false);
161
+
162
+ const confirmarRecusa = () => {
163
+ runQuery();
164
+ fecharModalRecusa();
165
+ };
166
+
85
167
  return (
86
168
  <CardContainer
87
169
  data-testid={testId}
@@ -108,7 +190,7 @@ export const InsuranceCard: React.FC<InsuranceCardProps> = ({
108
190
  onClose={() => setShowTimeline(false)}
109
191
  data={timelineItems}
110
192
  loading={isTimelineLoading}
111
- onRetry={() => fetchTimeline(idOrder)}
193
+ onRetry={fetchTimeline}
112
194
  />
113
195
  <HeaderRow>
114
196
  {isSupply && (
@@ -127,7 +209,14 @@ export const InsuranceCard: React.FC<InsuranceCardProps> = ({
127
209
  <InfoRow>
128
210
  <InfoLabel>Segurado</InfoLabel>
129
211
  <TruncatedValue>{seguradoName}</TruncatedValue>
130
- <InfoSubValue>{seguradoCnpj}</InfoSubValue>
212
+ <InfoSubValue>
213
+ {mask(
214
+ seguradoCnpj,
215
+ cnpj.isValid(seguradoCnpj)
216
+ ? '00.000.000/0000-00'
217
+ : '000.000.000-00'
218
+ )}
219
+ </InfoSubValue>
131
220
  </InfoRow>
132
221
  <InfoRow>
133
222
  <InfoLabel>Produto</InfoLabel>
@@ -138,7 +227,7 @@ export const InsuranceCard: React.FC<InsuranceCardProps> = ({
138
227
  <InfoLabel>
139
228
  {activeIndex === 0 ? 'Iniciado em' : 'Emitido em'}
140
229
  </InfoLabel>
141
- <InfoValue>{issuedDate}</InfoValue>
230
+ <InfoValue>{format(parseISO(issuedDate), 'dd/MM/yyyy')}</InfoValue>
142
231
  </InfoRow>
143
232
  <InfoRow>
144
233
  <InfoLabel>
@@ -149,14 +238,18 @@ export const InsuranceCard: React.FC<InsuranceCardProps> = ({
149
238
  </InfoRow>
150
239
  <InfoRow>
151
240
  <InfoLabel>Processo</InfoLabel>
152
- <ProcessValue>{processId}</ProcessValue>
241
+ <ProcessValue>
242
+ {processId
243
+ ? mask(processId || '', '0000000-00.0000.0.00.0000')
244
+ : '-'}
245
+ </ProcessValue>
153
246
  </InfoRow>
154
247
  <Actions>
155
248
  <DropdownWrapper>
156
249
  <ActionButton
157
250
  data-testid={`btn_minhas_emissoes_mais_informacoes_${processId}`}
158
251
  id={`btn_minhas_emissoes_mais_informacoes_${processId}`}
159
- onClick={() => toggleOpen?.(idOrder)}
252
+ onClick={toggleOpen}
160
253
  >
161
254
  Mais informações{' '}
162
255
  {isOpen ? <ChevronUp size={16} /> : <ChevronDown size={16} />}
@@ -174,7 +267,7 @@ export const InsuranceCard: React.FC<InsuranceCardProps> = ({
174
267
  )
175
268
  }
176
269
  onClick={() =>
177
- handleClick?.('linha_do_tempo', showTimelineToggle)
270
+ handleClick('linha_do_tempo', showTimelineToggle)
178
271
  }
179
272
  >
180
273
  Linha do tempo
@@ -190,9 +283,7 @@ export const InsuranceCard: React.FC<InsuranceCardProps> = ({
190
283
  )
191
284
  }
192
285
  onClick={() =>
193
- handleClick?.('continuar_emissao', () =>
194
- irParaContinuarEmissao(idOrder)
195
- )
286
+ handleClick('continuar_emissao', irParaContinuarEmissao)
196
287
  }
197
288
  >
198
289
  Continuar emissão
@@ -209,9 +300,7 @@ export const InsuranceCard: React.FC<InsuranceCardProps> = ({
209
300
  )
210
301
  }
211
302
  onClick={() =>
212
- handleClick?.('minuta', () =>
213
- downloadFile('MINUTE', 'true')
214
- )
303
+ handleClick('minuta', () => downloadFile('MINUTE', true))
215
304
  }
216
305
  >
217
306
  Baixar minuta
@@ -230,9 +319,7 @@ export const InsuranceCard: React.FC<InsuranceCardProps> = ({
230
319
  )
231
320
  }
232
321
  onClick={() =>
233
- handleClick?.('recusar_proposta', () =>
234
- abrirModalRecusarProposta(idOrder)
235
- )
322
+ handleClick('recusar_proposta', abrirModalRecusarProposta)
236
323
  }
237
324
  >
238
325
  Recusar proposta
@@ -251,9 +338,7 @@ export const InsuranceCard: React.FC<InsuranceCardProps> = ({
251
338
  )
252
339
  }
253
340
  onClick={() =>
254
- handleClick?.('excluir_proposta', () =>
255
- abrirModalExcluirProposta(idOrder)
256
- )
341
+ handleClick('excluir_proposta', abrirModalExcluirProposta)
257
342
  }
258
343
  >
259
344
  Excluir proposta
@@ -274,7 +359,7 @@ export const InsuranceCard: React.FC<InsuranceCardProps> = ({
274
359
  )
275
360
  }
276
361
  onClick={() =>
277
- handleClick?.('linha_do_tempo', showTimelineToggle)
362
+ handleClick('linha_do_tempo', showTimelineToggle)
278
363
  }
279
364
  >
280
365
  Linha do tempo
@@ -290,9 +375,7 @@ export const InsuranceCard: React.FC<InsuranceCardProps> = ({
290
375
  )
291
376
  }
292
377
  onClick={() =>
293
- handleClick?.('apolice', () =>
294
- downloadFile('POLICY', 'true')
295
- )
378
+ handleClick('apolice', () => downloadFile('POLICY', true))
296
379
  }
297
380
  >
298
381
  Baixar apólice
@@ -308,7 +391,7 @@ export const InsuranceCard: React.FC<InsuranceCardProps> = ({
308
391
  )
309
392
  }
310
393
  onClick={() =>
311
- handleClick?.('boleto', () => downloadFile('SLIP', 'true'))
394
+ handleClick('boleto', () => downloadFile('SLIP', true))
312
395
  }
313
396
  >
314
397
  Baixar boleto
@@ -324,7 +407,9 @@ export const InsuranceCard: React.FC<InsuranceCardProps> = ({
324
407
  )
325
408
  }
326
409
  onClick={() =>
327
- handleClick?.('certidoes', () => searchCerts(idInsurance!))
410
+ handleClick('certidoes', () =>
411
+ searchCerts(idInsurance!, idOrder)
412
+ )
328
413
  }
329
414
  >
330
415
  Baixar certidões
@@ -340,8 +425,8 @@ export const InsuranceCard: React.FC<InsuranceCardProps> = ({
340
425
  )
341
426
  }
342
427
  onClick={() =>
343
- handleClick?.('endosso', () =>
344
- onEndorsementClick(idInsurance!)
428
+ handleClick('endosso', () =>
429
+ onEndorsementClick('Umbrela Corp', idInsurance!)
345
430
  )
346
431
  }
347
432
  >
@@ -3,53 +3,38 @@ export type StatusVariant = 'primary' | 'success' | 'warning' | 'danger';
3
3
 
4
4
  export interface InsuranceCardProps {
5
5
  idGranto: string;
6
- idInterno: string;
7
6
  idOrder: string;
8
7
  idInsurance?: string;
8
+ idInterno: string;
9
9
  isSupply: boolean;
10
- hasMinute?: boolean;
10
+ hasMinute: boolean;
11
11
  statusLabel: string;
12
- statusVariant: string;
12
+ statusVariant: StatusVariant;
13
13
  seguradoName: string;
14
14
  seguradoCnpj: string;
15
- product: string;
15
+ product: any;
16
16
  issuedDate: string;
17
17
  totalValue: string;
18
- processId: string;
19
- activeIndex?: number;
18
+ processId?: string;
19
+ activeIndex: number;
20
20
  testId?: string;
21
21
  openCardId: string | null;
22
22
  setOpenCardId: (id: string | null) => void;
23
23
  runQuery: () => void;
24
- loadingItem: string | null;
25
- setLoadingItem: (id: string | null) => void;
26
- showRefuseModal: boolean;
27
- setShowRefuseModal: (value: boolean) => void;
28
- showExcludeModal: boolean;
29
- setShowExcludeModal: (value: boolean) => void;
30
- showTimeline: boolean;
31
- setShowTimeline: (value: boolean) => void;
32
- timelineItems: any[];
33
- setTimelineItems: (items: any[]) => void;
34
- isTimelineLoading: boolean;
35
- fetchTimeline: (idOrder: string) => Promise<void>;
36
- showTimelineToggle: () => void;
37
- toggleOpen: (idOrder: string) => void;
38
- productTitle?: string;
39
- productDescription?: string;
40
- downloadFile: (fileUrl: string, fileName: string) => void;
41
- searchCerts: (idOrder: string) => void;
42
- onEndorsementClick: (idOrder: string) => void;
43
- mutateStageOrder: (idOrder: string, stage: string) => Promise<void>;
44
- setData: (data: any) => void;
45
- queryClient: any;
46
- irParaContinuarEmissao: (idOrder: string) => void;
47
- abrirModalExcluirProposta: (idOrder: string) => void;
48
- fecharModalExclusao: () => void;
49
- confirmarExclusao: () => Promise<void>;
50
- abrirModalRecusarProposta: (idOrder: string) => void;
51
- fecharModalRecusa: () => void;
52
- confirmarRecusa: () => Promise<void>;
53
- handleClick?: (value: string, callback: () => void) => void;
54
- isAllowedByRoles?: any;
24
+ useDownloadAndSupport: any;
25
+ useDownloadFile: any;
26
+ useChangeOrderStageAsync: any;
27
+ useMyStore: any;
28
+ useQueryClient: any;
29
+ useGetTimeline: any;
30
+ useAuthStoreV2: any;
31
+ }
32
+
33
+ export interface MenuItemProps {
34
+ icon: React.ReactNode;
35
+ danger?: boolean;
36
+ children: React.ReactNode;
37
+ onClick?: () => void;
38
+ id?: string;
39
+ 'data-testid'?: string;
55
40
  }