@asdp/ferryui 0.1.22-dev.10844 → 0.1.22-dev.10850

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
@@ -4,7 +4,7 @@ import React, { forwardRef, useState, useRef, useEffect, useCallback, useMemo, F
4
4
  import { ArrowDownloadRegular, Dismiss24Regular, DismissRegular, SubtractRegular, AddRegular, DeleteRegular, InfoRegular, SearchRegular, ChevronDownRegular, ArrowRightRegular } from '@fluentui/react-icons';
5
5
  import { Container, Row, Col, Visible } from 'react-grid-system';
6
6
  import { Icon } from '@iconify/react';
7
- import { Controller, useForm, useWatch, useFieldArray } from 'react-hook-form';
7
+ import { Controller, useForm, useWatch } from 'react-hook-form';
8
8
  import PhoneInputComponent from 'react-phone-input-2';
9
9
  import Select from 'react-select';
10
10
  import { Calendar } from '@fluentui/react-calendar-compat';
@@ -12927,6 +12927,35 @@ var useStyles27 = makeStyles({
12927
12927
  }
12928
12928
  }
12929
12929
  });
12930
+ function OwnerWeightSync({
12931
+ setValue,
12932
+ onUpdateOwner,
12933
+ getValues,
12934
+ control,
12935
+ owner,
12936
+ ownerIndex
12937
+ }) {
12938
+ const cargoWeights = useWatch({
12939
+ control,
12940
+ name: (owner.cargoItems || []).map(
12941
+ (_, cargoIndex) => `owners.${ownerIndex}.cargo.${cargoIndex}.cargoWeight`
12942
+ )
12943
+ });
12944
+ const total = cargoWeights?.reduce(
12945
+ (sum, w) => sum + (Number(w) || 0),
12946
+ 0
12947
+ ) ?? 0;
12948
+ const current = Number(getValues(`owners.${ownerIndex}.estimatedWeight`)) || 0;
12949
+ useEffect(() => {
12950
+ if (current !== total) {
12951
+ setValue(`owners.${ownerIndex}.estimatedWeight`, total);
12952
+ onUpdateOwner(owner.id, {
12953
+ estimatedWeight: total
12954
+ });
12955
+ }
12956
+ }, [current, ownerIndex, total]);
12957
+ return null;
12958
+ }
12930
12959
  var CardVehicleOwnerForm = ({
12931
12960
  owners,
12932
12961
  hasLoad,
@@ -12971,38 +13000,6 @@ var CardVehicleOwnerForm = ({
12971
13000
  });
12972
13001
  setOpenCargoItems(allOpenItems);
12973
13002
  }, [owners]);
12974
- function OwnerWeightSync({
12975
- owner,
12976
- ownerIndex
12977
- }) {
12978
- const { fields } = useFieldArray({
12979
- control,
12980
- name: `owners.${ownerIndex}.cargoItems`
12981
- });
12982
- console.log(140, fields);
12983
- const cargoWeights = useWatch({
12984
- control,
12985
- name: fields.map(
12986
- (_, cargoIndex) => `owners.${ownerIndex}.cargoItems.${cargoIndex}.cargoWeight`
12987
- )
12988
- });
12989
- console.log(149, cargoWeights);
12990
- useEffect(() => {
12991
- const total = cargoWeights?.reduce(
12992
- (sum, w) => sum + (Number(w) || 0),
12993
- 0
12994
- ) ?? 0;
12995
- const current = Number(getValues(`owners.${ownerIndex}.estimatedWeight`)) || 0;
12996
- console.log(160, current, total);
12997
- if (current !== total) {
12998
- setValue(`owners.${ownerIndex}.estimatedWeight`, total);
12999
- onUpdateOwner(owner.id, {
13000
- estimatedWeight: total
13001
- });
13002
- }
13003
- }, [cargoWeights, ownerIndex, setValue, getValues]);
13004
- return null;
13005
- }
13006
13003
  return /* @__PURE__ */ jsxs(Card, { className: styles.card, children: [
13007
13004
  /* @__PURE__ */ jsxs("div", { className: styles.header, children: [
13008
13005
  /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", flex: 1 }, children: [
@@ -13027,7 +13024,7 @@ var CardVehicleOwnerForm = ({
13027
13024
  defaultOpenItems: owners.map((o) => String(o.id)),
13028
13025
  multiple: true,
13029
13026
  children: owners.map((owner, ownerIndex) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
13030
- /* @__PURE__ */ jsx(OwnerWeightSync, { owner, ownerIndex }),
13027
+ /* @__PURE__ */ jsx(OwnerWeightSync, { owner, ownerIndex, control, setValue, onUpdateOwner, getValues }),
13031
13028
  /* @__PURE__ */ jsxs(
13032
13029
  AccordionItem,
13033
13030
  {