@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.js CHANGED
@@ -12936,6 +12936,35 @@ var useStyles27 = reactComponents.makeStyles({
12936
12936
  }
12937
12937
  }
12938
12938
  });
12939
+ function OwnerWeightSync({
12940
+ setValue,
12941
+ onUpdateOwner,
12942
+ getValues,
12943
+ control,
12944
+ owner,
12945
+ ownerIndex
12946
+ }) {
12947
+ const cargoWeights = reactHookForm.useWatch({
12948
+ control,
12949
+ name: (owner.cargoItems || []).map(
12950
+ (_, cargoIndex) => `owners.${ownerIndex}.cargo.${cargoIndex}.cargoWeight`
12951
+ )
12952
+ });
12953
+ const total = cargoWeights?.reduce(
12954
+ (sum, w) => sum + (Number(w) || 0),
12955
+ 0
12956
+ ) ?? 0;
12957
+ const current = Number(getValues(`owners.${ownerIndex}.estimatedWeight`)) || 0;
12958
+ React.useEffect(() => {
12959
+ if (current !== total) {
12960
+ setValue(`owners.${ownerIndex}.estimatedWeight`, total);
12961
+ onUpdateOwner(owner.id, {
12962
+ estimatedWeight: total
12963
+ });
12964
+ }
12965
+ }, [current, ownerIndex, total]);
12966
+ return null;
12967
+ }
12939
12968
  var CardVehicleOwnerForm = ({
12940
12969
  owners,
12941
12970
  hasLoad,
@@ -12980,38 +13009,6 @@ var CardVehicleOwnerForm = ({
12980
13009
  });
12981
13010
  setOpenCargoItems(allOpenItems);
12982
13011
  }, [owners]);
12983
- function OwnerWeightSync({
12984
- owner,
12985
- ownerIndex
12986
- }) {
12987
- const { fields } = reactHookForm.useFieldArray({
12988
- control,
12989
- name: `owners.${ownerIndex}.cargoItems`
12990
- });
12991
- console.log(140, fields);
12992
- const cargoWeights = reactHookForm.useWatch({
12993
- control,
12994
- name: fields.map(
12995
- (_, cargoIndex) => `owners.${ownerIndex}.cargoItems.${cargoIndex}.cargoWeight`
12996
- )
12997
- });
12998
- console.log(149, cargoWeights);
12999
- React.useEffect(() => {
13000
- const total = cargoWeights?.reduce(
13001
- (sum, w) => sum + (Number(w) || 0),
13002
- 0
13003
- ) ?? 0;
13004
- const current = Number(getValues(`owners.${ownerIndex}.estimatedWeight`)) || 0;
13005
- console.log(160, current, total);
13006
- if (current !== total) {
13007
- setValue(`owners.${ownerIndex}.estimatedWeight`, total);
13008
- onUpdateOwner(owner.id, {
13009
- estimatedWeight: total
13010
- });
13011
- }
13012
- }, [cargoWeights, ownerIndex, setValue, getValues]);
13013
- return null;
13014
- }
13015
13012
  return /* @__PURE__ */ jsxRuntime.jsxs(reactComponents.Card, { className: styles.card, children: [
13016
13013
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.header, children: [
13017
13014
  /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", flex: 1 }, children: [
@@ -13036,7 +13033,7 @@ var CardVehicleOwnerForm = ({
13036
13033
  defaultOpenItems: owners.map((o) => String(o.id)),
13037
13034
  multiple: true,
13038
13035
  children: owners.map((owner, ownerIndex) => /* @__PURE__ */ jsxRuntime.jsxs(React__default.default.Fragment, { children: [
13039
- /* @__PURE__ */ jsxRuntime.jsx(OwnerWeightSync, { owner, ownerIndex }),
13036
+ /* @__PURE__ */ jsxRuntime.jsx(OwnerWeightSync, { owner, ownerIndex, control, setValue, onUpdateOwner, getValues }),
13040
13037
  /* @__PURE__ */ jsxRuntime.jsxs(
13041
13038
  reactComponents.AccordionItem,
13042
13039
  {