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

fix: strip denominations from indexId #288

Merged
merged 1 commit into from
Feb 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"))
}