@nerdjs/sales-kit 2.4.5 → 2.4.6

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.
Files changed (31) hide show
  1. package/dist/hooks/lep/lepActionBar.js +1 -1
  2. package/dist/hooks/lep/lepActionBar.js.map +1 -1
  3. package/dist/hooks/lep/loadEditPanel.js +1 -7
  4. package/dist/hooks/lep/loadEditPanel.js.map +1 -1
  5. package/dist/hooks/load/loadsSearchInput.d.ts +1 -0
  6. package/dist/hooks/load/loadsSearchInput.js +18 -1
  7. package/dist/hooks/load/loadsSearchInput.js.map +1 -1
  8. package/dist/hooks/quote/constants.js +1 -0
  9. package/dist/hooks/quote/constants.js.map +1 -1
  10. package/dist/hooks/quote/form.js +2 -2
  11. package/dist/hooks/quote/form.js.map +1 -1
  12. package/dist/hooks/quote/helpers.js +2 -1
  13. package/dist/hooks/quote/helpers.js.map +1 -1
  14. package/dist/hooks/quote/result.js +192 -203
  15. package/dist/hooks/quote/result.js.map +1 -1
  16. package/dist/locales/en/common.json +2 -1
  17. package/dist/locales/index.d.ts +1 -0
  18. package/dist/redux/quote/quoteAction.d.ts +1 -11
  19. package/dist/redux/quote/quoteAction.js +1 -19
  20. package/dist/redux/quote/quoteAction.js.map +1 -1
  21. package/dist/redux/quote/quoteCustomerPortalEndpoints.d.ts +4 -4
  22. package/dist/redux/quote/quoteCustomerPortalEndpoints.js +1 -1
  23. package/dist/redux/quote/quoteCustomerPortalEndpoints.js.map +1 -1
  24. package/dist/redux/quote/quoteReducer.d.ts +1 -3
  25. package/dist/redux/quote/quoteReducer.js +4 -14
  26. package/dist/redux/quote/quoteReducer.js.map +1 -1
  27. package/dist/redux/quote/quoteSalesEndpoints.d.ts +2 -2
  28. package/dist/redux/quote/quoteSelectors.d.ts +1 -11
  29. package/dist/redux/quote/quoteSelectors.js +2 -6
  30. package/dist/redux/quote/quoteSelectors.js.map +1 -1
  31. package/package.json +1 -1
@@ -1,22 +1,23 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { Button, Chip, Table, Typography, LinearProgress, Alert, Link, useColorScheme, Menu, MenuItem, Dropdown, MenuButton, Sheet, useTheme, Box, CircularProgress, Modal, ModalDialog, DialogActions, DialogContent, DialogTitle, Divider, Grid, Tooltip, Accordion, AccordionDetails, AccordionSummary, AccordionGroup, accordionClasses, IconButton, } from "@mui/joy";
2
+ import { Button, Chip, Table, Typography, LinearProgress, Alert, Link, useColorScheme, Menu, MenuItem, Dropdown, MenuButton, Sheet, useTheme, Box, CircularProgress, Modal, ModalDialog, DialogActions, DialogContent, DialogTitle, Divider, Grid, Tooltip, Accordion, AccordionDetails, AccordionSummary, AccordionGroup, accordionClasses, IconButton, FormControl, FormLabel, } from "@mui/joy";
3
3
  import { alpha, styled } from "@mui/system";
4
4
  import { LocalizationProvider, PickersDay, StaticDatePicker, } from "@mui/x-date-pickers";
5
5
  import { Fragment, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, } from "react";
6
6
  import salesKitI18n from "../../i18n";
7
7
  import { useTranslation } from "react-i18next";
8
8
  import { useDispatch, useSelector } from "react-redux";
9
- import { restartQuote, setCostBreakdownOpen, setFormOpen, setMarketCostOpen, setQuoteResult, setSelectedDate, setSelectedServiceLevel, } from "../../redux/quote";
10
- import { useLazyGetCostBreakdownQuery, useGetMarketCostQuery, useLazyGetMarketCostQuery, } from "../../redux/quote/quoteCustomerPortalEndpoints";
11
- import { costBreakdownOpenSelector, formOpenSelector, selectedDateSelector, selectedServiceLevelSelector, } from "../../redux/quote/quoteSelectors";
9
+ import { restartQuote, setCostBreakdownOpen, setCargoLiability, setFormOpen, setMarketCostOpen, setQuoteResult, setSelectedDate, setSelectedServiceLevel, } from "../../redux/quote";
10
+ import { useLazyGetCostBreakdownQuery, useGetMarketCostQuery, useLazyGetMarketCostQuery, useCalculateLoadLiabilityCostMutation, } from "../../redux/quote/quoteCustomerPortalEndpoints";
11
+ import { costBreakdownOpenSelector, cargoLiabilitySelector, formOpenSelector, quoteResultSelector, selectedDateSelector, selectedServiceLevelSelector, } from "../../redux/quote/quoteSelectors";
12
12
  import { SALES_QUOTE_EXPIRATION, CUSTOMER_PORTAL_QUOTE_EXPIRATION, LTL_DOC, TL_DOC, serviceLevelColors, serviceLevelIcons, usdFormatter, quoteResultToEmail, } from "./constants";
13
13
  import { DateTime } from "luxon";
14
14
  import { Link as RouterLink } from "react-router-dom";
15
15
  import { useHotkeys } from "react-hotkeys-hook";
16
16
  import { useGetCustomerCreditQuery } from "../../redux";
17
17
  import { nanoid } from "@reduxjs/toolkit";
18
- import { CustomAdapterLuxon } from "@nerdjs/nerd-ui";
18
+ import { CustomAdapterLuxon, NerdCurrencyField } from "@nerdjs/nerd-ui";
19
19
  const DATE_FORMAT = "LLL d";
20
+ const FIXED_CACHE_KEY = "cargoLiability";
20
21
  /**
21
22
  * QuoteResponse. A drawer that displays the quote response
22
23
  *
@@ -198,50 +199,29 @@ function ServiceLevelsDetails({ quoteResponse, }) {
198
199
  const { serviceLevels } = quoteResponse;
199
200
  const dispatch = useDispatch();
200
201
  const { t } = useTranslation("common", { i18n: salesKitI18n });
201
- // const [openEcoCargoLiabilityForm, setOpenEcoCargoLiabilityForm] =
202
- // useState(false);
203
- // const [openPreCargoLiabilityForm, setOpenPreCargoLiabilityForm] =
204
- // useState(false);
205
- // const [openGuaCargoLiabilityForm, setOpenGuaCargoLiabilityForm] =
206
- // useState(false);
202
+ const [openCargoLiabilityForm, setOpenCargoLiabilityForm] = useState({
203
+ open: false,
204
+ initialValue: 0,
205
+ });
207
206
  const { economy, guaranteed, premium } = useMemo(() => {
208
207
  const economy = serviceLevels?.find((s) => s.serviceLevel == "economy");
209
208
  const premium = serviceLevels?.find((s) => s.serviceLevel == "premium");
210
209
  const guaranteed = serviceLevels?.find((s) => s.serviceLevel == "guaranteed");
211
210
  return { economy, premium, guaranteed };
212
211
  }, [serviceLevels]);
213
- // const minEconomyLiabilityCoverage = useMemo(
214
- // () => economy?.liabilityCoverage || 0,
215
- // [economy?.liabilityCoverage]
216
- // );
217
- // const minPremiumLiabilityCoverage = useMemo(
218
- // () => premium?.liabilityCoverage || 0,
219
- // [premium?.liabilityCoverage]
220
- // );
221
- // const minGuaranteedLiabilityCoverage = useMemo(
222
- // () => guaranteed?.liabilityCoverage || 0,
223
- // [guaranteed?.liabilityCoverage]
224
- // );
225
- // const { data: economyCargoLiabilityCost } =
226
- // useCalculateLoadLiabilityCostMutation({ fixedCacheKey: "economy" })[1];
227
- // const { data: premiumCargoLiabilityCost } =
228
- // useCalculateLoadLiabilityCostMutation({ fixedCacheKey: "premium" })[1];
229
- // const { data: guaranteedCargoLiabilityCost } =
230
- // useCalculateLoadLiabilityCostMutation({ fixedCacheKey: "guaranteed" })[1];
231
- // const guaranteedCargoLiability = useSelector(
232
- // guaranteedCargoLiabilitySelector
233
- // );
234
- // const premiumCargoLiability = useSelector(premiumCargoLiabilitySelector);
235
- // const economyCargoLiability = useSelector(economyCargoLiabilitySelector);
236
- // useEffect(() => {
237
- // dispatch(setGuaranteedCargoLiability(minGuaranteedLiabilityCoverage));
238
- // dispatch(setPremiumCargoLiability(minPremiumLiabilityCoverage));
239
- // dispatch(setEconomyCargoLiability(minEconomyLiabilityCoverage));
240
- // }, [
241
- // minEconomyLiabilityCoverage,
242
- // minPremiumLiabilityCoverage,
243
- // minGuaranteedLiabilityCoverage,
244
- // ]);
212
+ const minEconomyLiabilityCoverage = useMemo(() => economy?.liabilityCoverage || 0, [economy?.liabilityCoverage]);
213
+ const minPremiumLiabilityCoverage = useMemo(() => premium?.liabilityCoverage || 0, [premium?.liabilityCoverage]);
214
+ const minGuaranteedLiabilityCoverage = useMemo(() => guaranteed?.liabilityCoverage || 0, [guaranteed?.liabilityCoverage]);
215
+ const { data: cargoLiabilityCost, reset } = useCalculateLoadLiabilityCostMutation({
216
+ fixedCacheKey: FIXED_CACHE_KEY,
217
+ })[1];
218
+ const cargoLiability = useSelector(cargoLiabilitySelector);
219
+ useEffect(() => {
220
+ return () => {
221
+ dispatch(setCargoLiability(0));
222
+ reset();
223
+ };
224
+ }, []);
245
225
  return (_jsx(Sheet, { sx: {
246
226
  borderRadius: "sm",
247
227
  boxShadow: "md",
@@ -275,7 +255,57 @@ function ServiceLevelsDetails({ quoteResponse, }) {
275
255
  }, children: t("global.Same Day Pickup") }), guaranteed && (_jsxs("td", { children: [_jsx(Typography, { children: "99.9%" }), _jsx(LinearProgress, { value: 99.9, determinate: true, thickness: 5 })] })), premium && (_jsxs("td", { children: [_jsx(Typography, { children: "85%" }), _jsx(LinearProgress, { value: 85, determinate: true, thickness: 5 })] })), economy && (_jsxs("td", { children: [_jsx(Typography, { children: "50%" }), _jsx(LinearProgress, { value: 50, determinate: true, thickness: 5 })] }))] }), _jsxs("tr", { children: [_jsx("th", { children: _jsx("i", { className: "fa-solid fa-truck-front" }) }), _jsx("th", { style: {
276
256
  whiteSpace: "normal",
277
257
  wordBreak: "break-word",
278
- }, children: t("global.Driver / Equipment Allocation") }), guaranteed && (_jsxs("td", { children: [_jsx(Typography, { children: "99.9%" }), _jsx(LinearProgress, { value: 99.9, determinate: true, thickness: 5 })] })), premium && (_jsxs("td", { children: [_jsx(Typography, { children: "85%" }), _jsx(LinearProgress, { value: 85, determinate: true, thickness: 5 })] })), economy && (_jsxs("td", { children: [_jsx(Typography, { children: "50%" }), _jsx(LinearProgress, { value: 50, determinate: true, thickness: 5 })] }))] }), _jsxs("tr", { children: [_jsx("th", {}), _jsx("th", { style: {
258
+ }, children: t("global.Driver / Equipment Allocation") }), guaranteed && (_jsxs("td", { children: [_jsx(Typography, { children: "99.9%" }), _jsx(LinearProgress, { value: 99.9, determinate: true, thickness: 5 })] })), premium && (_jsxs("td", { children: [_jsx(Typography, { children: "85%" }), _jsx(LinearProgress, { value: 85, determinate: true, thickness: 5 })] })), economy && (_jsxs("td", { children: [_jsx(Typography, { children: "50%" }), _jsx(LinearProgress, { value: 50, determinate: true, thickness: 5 })] }))] }), !quoteResponse.loadId && quoteResponse.type == "LTL" ? (_jsxs(_Fragment, { children: [_jsxs("tr", { children: [_jsx("th", {}), _jsxs("th", { style: {
259
+ whiteSpace: "normal",
260
+ wordBreak: "break-word",
261
+ }, children: ["Cargo Liability", _jsx(Button, { sx: {
262
+ mt: 0.5,
263
+ }, size: "sm", variant: "soft", onClick: () => setOpenCargoLiabilityForm({
264
+ open: true,
265
+ initialValue: minEconomyLiabilityCoverage,
266
+ }), startDecorator: _jsx("i", { className: "fa-solid fa-plus" }), children: "Add More" })] }), guaranteed && (_jsx("td", { children: _jsxs(Box, { display: "flex", flexDirection: "column", alignItems: "center", gap: 0.5, children: [_jsx(Chip, { color: cargoLiability > minGuaranteedLiabilityCoverage
267
+ ? "neutral"
268
+ : "primary", startDecorator: cargoLiability >
269
+ minGuaranteedLiabilityCoverage ? null : (_jsx("i", { className: "fa-solid fa-circle-check" })), sx: {
270
+ textDecoration: cargoLiability > minGuaranteedLiabilityCoverage
271
+ ? "line-through"
272
+ : undefined,
273
+ }, size: cargoLiability > minGuaranteedLiabilityCoverage
274
+ ? "sm"
275
+ : "md", children: usdFormatter.format(minGuaranteedLiabilityCoverage) }), cargoLiability > minGuaranteedLiabilityCoverage ? (_jsx(Chip, { color: "primary", startDecorator: _jsx("i", { className: "fa-solid fa-circle-check" }), children: usdFormatter.format(cargoLiability) })) : null] }) })), premium && (_jsx("td", { children: _jsxs(Box, { display: "flex", flexDirection: "column", alignItems: "center", gap: 0.5, children: [_jsx(Chip, { color: cargoLiability > minPremiumLiabilityCoverage
276
+ ? "neutral"
277
+ : "primary", startDecorator: cargoLiability >
278
+ minPremiumLiabilityCoverage ? null : (_jsx("i", { className: "fa-solid fa-circle-check" })), sx: {
279
+ textDecoration: cargoLiability > minPremiumLiabilityCoverage
280
+ ? "line-through"
281
+ : undefined,
282
+ }, size: cargoLiability > minPremiumLiabilityCoverage
283
+ ? "sm"
284
+ : "md", children: usdFormatter.format(minPremiumLiabilityCoverage) }), cargoLiability > minPremiumLiabilityCoverage ? (_jsx(Chip, { color: "primary", startDecorator: _jsx("i", { className: "fa-solid fa-circle-check" }), children: usdFormatter.format(cargoLiability) })) : null] }) })), economy && (_jsx("td", { children: _jsxs(Box, { display: "flex", flexDirection: "column", alignItems: "center", gap: 0.5, children: [_jsx(Chip, { color: cargoLiability > minEconomyLiabilityCoverage
285
+ ? "neutral"
286
+ : "primary", startDecorator: cargoLiability >
287
+ minEconomyLiabilityCoverage ? null : (_jsx("i", { className: "fa-solid fa-circle-check" })), sx: {
288
+ textDecoration: cargoLiability > minEconomyLiabilityCoverage
289
+ ? "line-through"
290
+ : undefined,
291
+ }, size: cargoLiability > minEconomyLiabilityCoverage
292
+ ? "sm"
293
+ : "md", children: usdFormatter.format(minEconomyLiabilityCoverage) }), cargoLiability > minEconomyLiabilityCoverage ? (_jsx(Chip, { color: "primary", startDecorator: _jsx("i", { className: "fa-solid fa-circle-check" }), children: usdFormatter.format(cargoLiability) })) : null] }) })), _jsx(EditCargoLiabilityModal, { onClose: () => setOpenCargoLiabilityForm({ open: false, initialValue: 0 }), initialValue: openCargoLiabilityForm.initialValue, open: openCargoLiabilityForm.open, value: cargoLiability, setValue: (v) => dispatch(setCargoLiability(v)) })] }), _jsxs("tr", { children: [_jsx("th", {}), _jsx("th", { style: {
294
+ whiteSpace: "normal",
295
+ wordBreak: "break-word",
296
+ }, children: "Cargo Liability Cost" }), guaranteed && (_jsx("td", { children: _jsxs(Box, { display: "flex", alignItems: "center", flexDirection: "column", gap: 0.5, children: [_jsx(Chip, { sx: {
297
+ textDecoration: cargoLiabilityCost?.guaranteed
298
+ ? "line-through"
299
+ : undefined,
300
+ }, color: cargoLiabilityCost?.guaranteed ? "neutral" : "primary", size: "sm", startDecorator: cargoLiabilityCost?.guaranteed ? undefined : (_jsx("i", { className: "fa-solid fa-circle-check" })), children: "Included" }), cargoLiabilityCost?.guaranteed ? (_jsx(Chip, { color: "primary", size: "sm", startDecorator: _jsx("i", { className: "fa-solid fa-circle-check" }), children: usdFormatter.format(cargoLiabilityCost.guaranteed || 0) })) : null] }) })), premium && (_jsx("td", { children: _jsxs(Box, { display: "flex", alignItems: "center", flexDirection: "column", gap: 0.5, children: [_jsx(Chip, { sx: {
301
+ textDecoration: cargoLiabilityCost?.premium
302
+ ? "line-through"
303
+ : undefined,
304
+ }, color: cargoLiabilityCost?.premium ? "neutral" : "primary", size: "sm", startDecorator: cargoLiabilityCost?.premium ? undefined : (_jsx("i", { className: "fa-solid fa-circle-check" })), children: "Included" }), cargoLiabilityCost?.premium ? (_jsx(Chip, { color: "primary", size: "sm", startDecorator: _jsx("i", { className: "fa-solid fa-circle-check" }), children: usdFormatter.format(cargoLiabilityCost.premium || 0) })) : null] }) })), economy && (_jsx("td", { children: _jsxs(Box, { display: "flex", alignItems: "center", flexDirection: "column", gap: 0.5, children: [_jsx(Chip, { sx: {
305
+ textDecoration: cargoLiabilityCost?.economy
306
+ ? "line-through"
307
+ : undefined,
308
+ }, color: cargoLiabilityCost?.economy ? "neutral" : "primary", size: "sm", startDecorator: cargoLiabilityCost?.economy ? undefined : (_jsx("i", { className: "fa-solid fa-circle-check" })), children: "Included" }), cargoLiabilityCost?.economy ? (_jsx(Chip, { color: "primary", size: "sm", startDecorator: _jsx("i", { className: "fa-solid fa-circle-check" }), children: usdFormatter.format(cargoLiabilityCost.economy || 0) })) : null] }) }))] })] })) : null, _jsxs("tr", { children: [_jsx("th", {}), _jsx("th", { style: {
279
309
  whiteSpace: "normal",
280
310
  wordBreak: "break-word",
281
311
  }, children: t("global.Base") }), guaranteed && _jsx("td", { children: usdFormatter.format(guaranteed.baseRate) }), premium && _jsx("td", { children: usdFormatter.format(premium.baseRate) }), economy && _jsx("td", { children: usdFormatter.format(economy.baseRate) })] }), _jsxs("tr", { children: [_jsx("th", {}), _jsx("th", { style: {
@@ -287,7 +317,19 @@ function ServiceLevelsDetails({ quoteResponse, }) {
287
317
  }, children: t("global.Extra") }), guaranteed && _jsx("td", { children: usdFormatter.format(guaranteed.extra) }), premium && _jsx("td", { children: usdFormatter.format(premium.extra) }), economy && _jsx("td", { children: usdFormatter.format(economy.extra) })] }), _jsxs("tr", { children: [_jsx("th", {}), _jsx("th", { style: {
288
318
  whiteSpace: "normal",
289
319
  wordBreak: "break-word",
290
- }, children: t("global.Total") }), guaranteed && (_jsx("td", { children: usdFormatter.format(guaranteed.totalRate) })), premium && (_jsx("td", { children: usdFormatter.format(premium.totalRate) })), economy && (_jsx("td", { children: usdFormatter.format(economy.totalRate) }))] })] }), _jsx("tfoot", { style: {
320
+ }, children: t("global.Total") }), guaranteed && (_jsx("td", { children: _jsxs(Box, { display: "flex", alignItems: "center", flexDirection: "column", gap: 0.5, children: [_jsx(Chip, { size: "sm", sx: {
321
+ textDecoration: cargoLiabilityCost?.guaranteed
322
+ ? "line-through"
323
+ : undefined,
324
+ }, color: !cargoLiabilityCost?.guaranteed ? "primary" : "neutral", startDecorator: !cargoLiabilityCost?.guaranteed ? (_jsx("i", { className: "fa-solid fa-circle-check" })) : null, children: usdFormatter.format(guaranteed.totalRate) }), cargoLiabilityCost?.guaranteed ? (_jsx(Chip, { size: "sm", color: "primary", startDecorator: _jsx("i", { className: "fa-solid fa-circle-check" }), children: usdFormatter.format(guaranteed.totalRate + cargoLiabilityCost.guaranteed) })) : null] }) })), premium && (_jsx("td", { children: _jsxs(Box, { display: "flex", alignItems: "center", flexDirection: "column", gap: 0.5, children: [_jsx(Chip, { size: "sm", sx: {
325
+ textDecoration: cargoLiabilityCost?.premium
326
+ ? "line-through"
327
+ : undefined,
328
+ }, color: !cargoLiabilityCost?.premium ? "primary" : "neutral", startDecorator: !cargoLiabilityCost?.premium ? (_jsx("i", { className: "fa-solid fa-circle-check" })) : null, children: usdFormatter.format(premium.totalRate) }), cargoLiabilityCost?.premium ? (_jsx(Chip, { size: "sm", color: "primary", startDecorator: _jsx("i", { className: "fa-solid fa-circle-check" }), children: usdFormatter.format(premium.totalRate + cargoLiabilityCost.premium) })) : null] }) })), economy && (_jsx("td", { children: _jsxs(Box, { display: "flex", alignItems: "center", flexDirection: "column", gap: 0.5, children: [_jsx(Chip, { size: "sm", sx: {
329
+ textDecoration: cargoLiabilityCost?.economy
330
+ ? "line-through"
331
+ : undefined,
332
+ }, color: !cargoLiabilityCost?.economy ? "primary" : "neutral", startDecorator: !cargoLiabilityCost?.economy ? (_jsx("i", { className: "fa-solid fa-circle-check" })) : null, children: usdFormatter.format(economy.totalRate) }), cargoLiabilityCost?.economy ? (_jsx(Chip, { size: "sm", color: "primary", startDecorator: _jsx("i", { className: "fa-solid fa-circle-check" }), children: usdFormatter.format(economy.totalRate + cargoLiabilityCost.economy) })) : null] }) }))] })] }), _jsx("tfoot", { style: {
291
333
  height: 70,
292
334
  }, children: _jsxs("tr", { children: [_jsx("th", {}), _jsx("th", { style: {
293
335
  borderBottomRightRadius: 0,
@@ -314,133 +356,84 @@ function ServiceLevelsDetails({ quoteResponse, }) {
314
356
  ? ` - ${DateTime.fromFormat(economy.to, "yyyy-L-d").toFormat(DATE_FORMAT)}`
315
357
  : []] })] }) }) }))] }) })] }) }));
316
358
  }
317
- // const EditCargoLiabilityModal = ({
318
- // value,
319
- // setValue,
320
- // open,
321
- // onClose,
322
- // minValue,
323
- // serviceLevel,
324
- // }: {
325
- // value: number;
326
- // setValue: (value: number) => void;
327
- // open: boolean;
328
- // onClose: () => void;
329
- // minValue: number;
330
- // serviceLevel: "economy" | "premium" | "guaranteed";
331
- // }) => {
332
- // const { t } = useTranslation("common", { i18n: salesKitI18n });
333
- // const [_value, _setValue] = useState<number | undefined>(value);
334
- // const [error, setError] = useState(false);
335
- // const [calculateCost, { isLoading }] = useCalculateLoadLiabilityCostMutation({
336
- // fixedCacheKey: serviceLevel,
337
- // });
338
- // const result = useSelector(quoteResultSelector);
339
- // const handleSave = () => {
340
- // if (result && _value !== undefined) {
341
- // calculateCost({
342
- // amount: _value,
343
- // weight: result?.weight,
344
- // })
345
- // .unwrap()
346
- // .then(() => {
347
- // setValue(_value);
348
- // handleClose();
349
- // })
350
- // .catch(() => {
351
- // return;
352
- // });
353
- // }
354
- // };
355
- // const handleClose = () => {
356
- // onClose();
357
- // _setValue(undefined);
358
- // };
359
- // useEffect(() => {
360
- // _setValue(value);
361
- // }, [open]);
362
- // return (
363
- // <Modal open={open} onClose={handleClose}>
364
- // <ModalDialog
365
- // layout="center"
366
- // sx={(theme) => ({
367
- // width: 450,
368
- // [theme.breakpoints.only("xs")]: {
369
- // top: 0,
370
- // left: 0,
371
- // right: 0,
372
- // bottom: 0,
373
- // border: 0,
374
- // borderRadius: 0,
375
- // transform: "initial",
376
- // maxWidth: "initial",
377
- // maxHeight: "initial",
378
- // width: "initial",
379
- // },
380
- // })}
381
- // >
382
- // <DialogTitle>Cargo Liability</DialogTitle>
383
- // <DialogContent>
384
- // <Typography level="body-sm">
385
- // The minimum and included cargo liability amount for the selected
386
- // service level is{" "}
387
- // <Typography level="body-sm" color="primary" fontWeight={"md"}>
388
- // {usdFormatter.format(minValue)}
389
- // </Typography>
390
- // . Feel free to increase it; the cost will be calculated
391
- // automatically.
392
- // </Typography>
393
- // <Box mt={1}>
394
- // <FormControl>
395
- // <FormLabel>Cargo Liability</FormLabel>
396
- // <NerdCurrencyField
397
- // value={_value}
398
- // inputProps={{
399
- // fullWidth: true,
400
- // error,
401
- // endDecorator:
402
- // _value !== minValue ? (
403
- // <Tooltip title="Reset" size="sm">
404
- // <IconButton
405
- // size="sm"
406
- // onClick={() => _setValue(minValue)}
407
- // >
408
- // <i className="fa-solid fa-xmark" />
409
- // </IconButton>
410
- // </Tooltip>
411
- // ) : null,
412
- // }}
413
- // onChange={(v) => {
414
- // _setValue(v);
415
- // if (!v || v < minValue) setError(true);
416
- // else setError(false);
417
- // }}
418
- // />
419
- // <FormHelperText>
420
- // {error
421
- // ? `The minimum amount is ${usdFormatter.format(minValue)}`
422
- // : ""}
423
- // </FormHelperText>
424
- // </FormControl>
425
- // </Box>
426
- // </DialogContent>
427
- // <DialogActions>
428
- // <Button
429
- // loading={isLoading}
430
- // color="primary"
431
- // onClick={handleSave}
432
- // disabled={error}
433
- // >
434
- // {t("global.Confirm")}
435
- // </Button>
436
- // <Button color="neutral" variant="soft" onClick={handleClose}>
437
- // {t("global.Cancel")}
438
- // </Button>
439
- // </DialogActions>
440
- // </ModalDialog>
441
- // </Modal>
442
- // );
443
- // };
359
+ const EditCargoLiabilityModal = ({ value, setValue, open, onClose, initialValue, }) => {
360
+ const { t } = useTranslation("common", { i18n: salesKitI18n });
361
+ const [_value, _setValue] = useState(value ? value : undefined);
362
+ const [calculateCost] = useCalculateLoadLiabilityCostMutation({
363
+ fixedCacheKey: FIXED_CACHE_KEY,
364
+ });
365
+ const result = useSelector(quoteResultSelector);
366
+ //Cannot use the isLoading attribute from the useCalculateLoadLiabilityCostMutation hook
367
+ const [isLoading, setIsLoading] = useState(false);
368
+ const [isLoading2, setIsLoading2] = useState(false);
369
+ const handleSave = () => {
370
+ if (result && _value !== undefined) {
371
+ setIsLoading(true);
372
+ calculateCost({
373
+ statedValue: _value,
374
+ quoteID: result.id,
375
+ })
376
+ .unwrap()
377
+ .then(() => {
378
+ setValue(_value);
379
+ handleClose();
380
+ })
381
+ .catch(() => {
382
+ return;
383
+ })
384
+ .finally(() => setIsLoading(false));
385
+ }
386
+ };
387
+ const handleReset = () => {
388
+ if (result) {
389
+ setIsLoading2(true);
390
+ calculateCost({
391
+ statedValue: 0,
392
+ quoteID: result.id,
393
+ })
394
+ .unwrap()
395
+ .then(() => {
396
+ setValue(0);
397
+ handleClose();
398
+ })
399
+ .catch(() => {
400
+ return;
401
+ })
402
+ .finally(() => setIsLoading2(false));
403
+ }
404
+ };
405
+ const handleClose = () => {
406
+ onClose();
407
+ _setValue(value ? value : undefined);
408
+ };
409
+ useEffect(() => {
410
+ _setValue(value ? value : undefined);
411
+ }, [open]);
412
+ return (_jsx(Modal, { open: open, onClose: handleClose, children: _jsxs(ModalDialog, { layout: "center", sx: (theme) => ({
413
+ width: 450,
414
+ [theme.breakpoints.only("xs")]: {
415
+ top: 0,
416
+ left: 0,
417
+ right: 0,
418
+ bottom: 0,
419
+ border: 0,
420
+ borderRadius: 0,
421
+ transform: "initial",
422
+ maxWidth: "initial",
423
+ maxHeight: "initial",
424
+ width: "initial",
425
+ },
426
+ }), children: [_jsx(DialogTitle, { children: "Cargo Liability" }), _jsx(DialogContent, { children: _jsxs("form", { onSubmit: (event) => {
427
+ event.preventDefault();
428
+ if (_value)
429
+ handleSave();
430
+ }, children: [_jsx(Typography, { level: "body-sm", children: "Feel free to increase the Cargo Liability; the cost will be calculated automatically." }), _jsx(Box, { mt: 1, children: _jsxs(FormControl, { children: [_jsx(FormLabel, { children: "Cargo Liability" }), _jsx(NerdCurrencyField, { value: _value, inputProps: {
431
+ fullWidth: true,
432
+ placeholder: usdFormatter.format(initialValue).substring(1),
433
+ }, onChange: (v) => {
434
+ _setValue(v);
435
+ } })] }) })] }) }), _jsxs(DialogActions, { children: [_jsx(Button, { loading: isLoading, color: "primary", onClick: handleSave, disabled: !_value, children: t("global.Confirm") }), _jsx(Button, { color: "neutral", variant: "soft", onClick: handleClose, children: t("global.Cancel") }), _jsx(Button, { loading: isLoading2, color: "neutral", variant: "soft", onClick: handleReset, children: t("global.Reset") })] })] }) }));
436
+ };
444
437
  /**
445
438
  * Quote toolbar. Contains actions like restart, run quote or find a quote.
446
439
  *
@@ -741,26 +734,22 @@ export const Summary = ({ handleOnTenderLoadClick, customerPortal, response, bod
741
734
  })
742
735
  : false;
743
736
  const { data: customerCredit } = useGetCustomerCreditQuery(response?.customerId || 0, { skip: !response?.customerId || customerPortal });
744
- // const { data: _cargoLiabilityCost } = useCalculateLoadLiabilityCostMutation({
745
- // fixedCacheKey: selectedServiceLevel?.serviceLevel,
746
- // })[1];
747
- // const cargoLiabilityCost = useMemo(() => {
748
- // switch (selectedServiceLevel?.serviceLevel) {
749
- // case "economy":
750
- // return _cargoLiabilityCost?.economy || 0;
751
- // case "premium":
752
- // return _cargoLiabilityCost?.premium || 0;
753
- // case "guaranteed":
754
- // return _cargoLiabilityCost?.guaranteed || 0;
755
- // default:
756
- // return 0;
757
- // }
758
- // }, [_cargoLiabilityCost]);
759
- // const guaranteedCargoLiability = useSelector(
760
- // guaranteedCargoLiabilitySelector
761
- // );
762
- // const premiumCargoLiability = useSelector(premiumCargoLiabilitySelector);
763
- // const economyCargoLiability = useSelector(economyCargoLiabilitySelector);
737
+ const { data: _cargoLiabilityCost } = useCalculateLoadLiabilityCostMutation({
738
+ fixedCacheKey: FIXED_CACHE_KEY,
739
+ })[1];
740
+ const cargoLiabilityCost = useMemo(() => {
741
+ switch (selectedServiceLevel?.serviceLevel) {
742
+ case "economy":
743
+ return _cargoLiabilityCost?.economy || 0;
744
+ case "premium":
745
+ return _cargoLiabilityCost?.premium || 0;
746
+ case "guaranteed":
747
+ return _cargoLiabilityCost?.guaranteed || 0;
748
+ default:
749
+ return 0;
750
+ }
751
+ }, [_cargoLiabilityCost, selectedServiceLevel?.serviceLevel]);
752
+ const cargoLiability = useSelector(cargoLiabilitySelector);
764
753
  if (!selectedDate || !selectedServiceLevel)
765
754
  return null;
766
755
  return (_jsxs(Sheet, { sx: { p: 2, borderRadius: "sm", boxShadow: "md" }, children: [_jsxs(Typography, { level: "title-lg", children: [_jsx("i", { className: "fa-duotone fa-truck pright" }), " ", t("global.Summary")] }), _jsxs(Grid, { container: true, spacing: 1, rowGap: 1.5, sx: {
@@ -771,11 +760,19 @@ export const Summary = ({ handleOnTenderLoadClick, customerPortal, response, bod
771
760
  ? DateTime.fromFormat(from.date, "yyyy-L-d").toFormat(DATE_FORMAT)
772
761
  : "" }) })] }), _jsxs(Grid, { xs: 4, container: true, children: [_jsxs(Grid, { xs: 12, children: [_jsx("i", { className: "fa-regular fa-arrow-down" }), _jsx(Typography, { ml: 1, display: "inline", level: "body-sm", children: t("global.To") })] }), _jsx(Grid, { xs: 12, children: _jsx(Typography, { children: to?.address.line1 || t("global.Unknown Location") }) }), _jsx(Grid, { xs: 12, children: _jsxs(Typography, { children: [to?.city, ", ", to?.state] }) }), _jsx(Grid, { xs: 12, children: _jsx(Typography, { children: to?.zip }) }), _jsx(Grid, { xs: 12, children: _jsx(Chip, { startDecorator: _jsx("i", { className: "fa-solid fa-calendar-days" }), variant: "soft", children: selectedServiceLevel.serviceLevel == "guaranteed"
773
762
  ? selectedDate?.toFormat(DATE_FORMAT)
774
- : `${DateTime.fromFormat(selectedServiceLevel.from, "yyyy-L-d").toFormat(DATE_FORMAT)} - ${DateTime.fromFormat(selectedServiceLevel.to, "yyyy-L-d").toFormat(DATE_FORMAT)}` }) })] })] }), _jsxs(Grid, { xs: 12, children: [_jsx(Typography, { level: "title-lg", children: t("global.Costs") }), _jsxs(Table, { children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: t("global.Service Level") }), _jsx("th", { children: t("global.Description") }), _jsx("th", { children: t("global.Base Rate") }), _jsx("th", { children: t("global.Fuel Rate") }), _jsx("th", { children: t("global.Extra") })] }) }), _jsx("tbody", { children: _jsxs("tr", { children: [_jsx("td", { children: _jsx("img", { src: selectedServiceLevel.serviceLevel === "guaranteed"
763
+ : `${DateTime.fromFormat(selectedServiceLevel.from, "yyyy-L-d").toFormat(DATE_FORMAT)} - ${DateTime.fromFormat(selectedServiceLevel.to, "yyyy-L-d").toFormat(DATE_FORMAT)}` }) })] })] }), _jsxs(Grid, { xs: 12, children: [_jsx(Typography, { level: "title-lg", children: t("global.Costs") }), _jsxs(Table, { children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: t("global.Service Level") }), _jsx("th", { children: t("global.Description") }), !response?.loadId && response?.type == "LTL" ? (_jsx("th", { style: {
764
+ width: 150,
765
+ }, children: "Cargo Liability Cost" })) : null, _jsx("th", { children: t("global.Base Rate") }), _jsx("th", { children: t("global.Fuel Rate") }), _jsx("th", { children: t("global.Extra") })] }) }), _jsx("tbody", { children: _jsxs("tr", { children: [_jsx("td", { children: _jsx("img", { src: selectedServiceLevel.serviceLevel === "guaranteed"
775
766
  ? response?.getGuaranteedIcon()
776
767
  : selectedServiceLevel.serviceLevel === "premium"
777
768
  ? response?.getPremiumIcon()
778
- : response?.getEconomyIcon(), style: { height: 20 } }) }), _jsx("td", { children: selectedServiceLevel?.description }), _jsx("td", { children: usdFormatter.format(selectedServiceLevel.baseRate) }), _jsx("td", { children: usdFormatter.format(selectedServiceLevel.fuelRate) }), _jsx("td", { children: usdFormatter.format(selectedServiceLevel.extra) })] }) })] })] }), _jsxs(Grid, { xs: 12, textAlign: "right", justifyContent: "end", container: true, children: [_jsxs(Grid, { children: [_jsx(Typography
769
+ : response?.getEconomyIcon(), style: { height: 20 } }) }), _jsx("td", { children: selectedServiceLevel?.description }), !response?.loadId && response?.type == "LTL" ? (_jsx("td", { children: _jsx(Chip, { size: "sm", color: cargoLiabilityCost ? "primary" : "neutral", sx: {
770
+ backgroundColor: cargoLiabilityCost
771
+ ? undefined
772
+ : "inherit",
773
+ }, children: cargoLiabilityCost === 0
774
+ ? "Included"
775
+ : usdFormatter.format(cargoLiabilityCost) }) })) : null, _jsx("td", { children: usdFormatter.format(selectedServiceLevel.baseRate) }), _jsx("td", { children: usdFormatter.format(selectedServiceLevel.fuelRate) }), _jsx("td", { children: usdFormatter.format(selectedServiceLevel.extra) })] }) })] })] }), _jsxs(Grid, { xs: 12, textAlign: "right", justifyContent: "end", container: true, children: [_jsxs(Grid, { children: [_jsx(Typography
779
776
  // sx={{
780
777
  // pr: 1,
781
778
  // }}
@@ -802,15 +799,7 @@ export const Summary = ({ handleOnTenderLoadClick, customerPortal, response, bod
802
799
  selectedServiceLevel.totalRate
803
800
  ? customerCredit.availableCredit -
804
801
  selectedServiceLevel.totalRate
805
- : undefined
806
- // cargoLiabilityCost !== 0
807
- // ? selectedServiceLevel.serviceLevel === "economy"
808
- // ? economyCargoLiability
809
- // : selectedServiceLevel.serviceLevel === "guaranteed"
810
- // ? guaranteedCargoLiability
811
- // : premiumCargoLiability
812
- // : undefined
813
- );
802
+ : undefined, cargoLiabilityCost !== 0 ? cargoLiability : undefined);
814
803
  dispatch(restartQuote());
815
804
  dispatch(setQuoteResult(undefined));
816
805
  }