Skip to content

Commit

Permalink
(fix) Fix undefined errors thrown when clearing/deselecting values fr…
Browse files Browse the repository at this point in the history
…om selectors (#40)

thanks @makombe
  • Loading branch information
makombe authored Dec 12, 2023
1 parent f6e0be6 commit ae0bb8a
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const PreferredVendorSelector = <T,>(
items={sourcesList || []}
onChange={(data: { selectedItem: StockSource }) => {
props.onPreferredVendorChange?.(data.selectedItem);
onChange(data.selectedItem.uuid);
onChange(data.selectedItem?.uuid);
}}
initialSelectedItem={
sourcesList?.find((p) => p.uuid === props.preferredVendorUuid) || {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const StockItemCategorySelector = <T,>(
items={categories || []}
onChange={(data: { selectedItem: Concept }) => {
props.onCategoryUuidChange?.(data.selectedItem);
onChange(data.selectedItem.uuid);
onChange(data.selectedItem?.uuid);
}}
initialSelectedItem={
categories?.find((p) => p.uuid === props.categoryUuid) || {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ const BaseOperationDetails: React.FC<BaseOperationDetailsProps> = ({
errors?.responsiblePersonUuid?.message
}
onUserChanged={(user) => {
if (user.uuid === otherUser.uuid) {
if (user?.uuid === otherUser.uuid) {
setIsOtherUser(true);
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ const StockItemsAdditionRow: React.FC<StockItemsAdditionRowProps> = ({
handleStockItemChange(index, item);
setValue(
`stockItems.${index}.packagingUnits`,
item.packagingUnits
item?.packagingUnits
);
setStockItemUuid(item.uuid);
setStockItemUuid(item?.uuid);
}}
/>
)}
Expand Down Expand Up @@ -192,12 +192,12 @@ const StockItemsAdditionRow: React.FC<StockItemsAdditionRowProps> = ({
<BatchNoSelector
batchUuid={row?.stockBatchUuid}
onBatchNoChanged={(item) => {
setValue(`stockItems.${index}.batchNo`, item.batchNo);
setValue(`stockItems.${index}.batchNo`, item?.batchNo);
setValue(
`stockItems.${index}.expiration`,
item.expiration
item?.expiration
);
setStockItemExpiy(item.expiration);
setStockItemExpiy(item?.expiration);
}}
placeholder={"Filter..."}
invalid={!!errors?.stockItems?.[index]?.stockBatchUuid}
Expand Down Expand Up @@ -288,7 +288,7 @@ const StockItemsAdditionRow: React.FC<StockItemsAdditionRowProps> = ({
onStockPackageChanged={(selectedItem) => {
setValue(
`stockItems.${index}.stockItemPackagingUOMUuid`,
selectedItem.uuid
selectedItem?.uuid
);
}}
placeholder={"Filter..."}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const BatchNoSelector = <T,>(props: BatchNoSelectorProps<T>) => {
items={stockItemBatchNos || []}
onChange={(data: { selectedItem?: StockBatchDTO }) => {
props.onBatchNoChanged?.(data.selectedItem);
onChange(data.selectedItem.uuid);
onChange(data.selectedItem?.uuid);
}}
initialSelectedItem={
stockItemBatchNos?.find((p) => p.uuid === props.batchUuid) ?? ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const PartySelector = <T,>(props: PartySelectorProps<T>) => {
items={props.parties}
onChange={(data: { selectedItem: Party }) => {
props.onPartyChange?.(data.selectedItem);
onChange(data.selectedItem.uuid);
onChange(data.selectedItem?.uuid);
}}
initialSelectedItem={
props.parties?.find((p) => p.uuid === props.partyUuid) || {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ const QtyUomSelector = <T,>(props: QtyUomSelectorProps<T>) => {
controllerName={props.controllerName}
id={props.name}
size={"sm"}
items={item.packagingUnits || []}
items={item?.packagingUnits || []}
onChange={(data: { selectedItem?: StockItemPackagingUOMDTO }) => {
props.onStockPackageChanged?.(data.selectedItem);
onChange(data.selectedItem.uuid);
onChange(data.selectedItem?.uuid);
}}
initialSelectedItem={
item.packagingUnits?.find(
item?.packagingUnits?.find(
(p) => p.uuid === props.stockItemUuid
) ?? ""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const StockItemSelector = <T,>(props: StockItemSelectorProps<T>) => {
items={stockItemsList || []}
onChange={(data: { selectedItem: StockItemDTO }) => {
props.onStockItemChanged?.(data.selectedItem);
onChange(data.selectedItem.uuid);
onChange(data.selectedItem?.uuid);
}}
initialSelectedItem={
stockItemsList?.find((p) => p.uuid === props.stockItemUuid) ?? ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const UsersSelector = <T,>(props: UsersSelectorProps<T>) => {
items={userList || []}
onChange={(data: { selectedItem: User }) => {
props.onUserChanged?.(data.selectedItem);
onChange(data.selectedItem.uuid);
onChange(data.selectedItem?.uuid);
}}
initialSelectedItem={
userList?.find((p) => p.uuid === props.userUuid) ?? ""
Expand Down

0 comments on commit ae0bb8a

Please sign in to comment.