Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
fix: strip denominations in EditDenominationsModal from indexId (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
zakariaelas authored Feb 1, 2022
1 parent 27f3430 commit 0fd97e0
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/components/organisms/edit-denominations-modal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from "lodash"
import * as React from "react"
import { v4 as uuidv4 } from "uuid"
import Button from "../../fundamentals/button"
Expand All @@ -22,12 +23,6 @@ type EditDenominationsModalProps = {
currencyCodes?: string[]
}

const augmentWithId = (obj) => ({ ...obj, indexId: uuidv4() })

const augmentWithIds = (list) => {
return list.map(augmentWithId)
}

const EditDenominationsModal = ({
defaultDenominations = [],
onSubmit,
Expand Down Expand Up @@ -80,6 +75,14 @@ const EditDenominationsModal = ({
setDenominations([...denominations, augmentWithId(newDenomination)])
}

const submitHandler = () => {
const strippedDenominations = stripDenominationFromIndexId(denominations)

if (onSubmit) {
onSubmit(strippedDenominations)
}
}

return (
<Modal handleClose={handleClose}>
<Modal.Body>
Expand Down Expand Up @@ -151,7 +154,7 @@ const EditDenominationsModal = ({
variant="primary"
size="small"
className="mr-2 min-w-[130px] justify-center"
onClick={() => onSubmit(denominations)}
onClick={submitHandler}
>
Save
</Button>
Expand All @@ -163,3 +166,13 @@ const EditDenominationsModal = ({
}

export default EditDenominationsModal

const augmentWithId = (obj) => ({ ...obj, indexId: uuidv4() })

const augmentWithIds = (list) => {
return list.map(augmentWithId)
}

const stripDenominationFromIndexId = (list) => {
return list.map((element) => _.omit(element, "indexId"))
}

0 comments on commit 0fd97e0

Please sign in to comment.