Skip to content

Commit

Permalink
add currency to monetary type
Browse files Browse the repository at this point in the history
  • Loading branch information
ciur committed Oct 9, 2024
1 parent dd9cdb8 commit 927c87e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
15 changes: 15 additions & 0 deletions ui2/src/cconstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,18 @@ export const CUSTOM_FIELD_DATA_TYPES: Array<CustomFieldDataType> = [
"documentlink",
"select"
]

export const CURRENCIES = [
"CHF",
"CZK",
"DKK",
"EUR",
"GBP",
"HUF",
"ISK",
"NOK",
"USD",
"RON",
"RUB",
"SEK"
]
33 changes: 29 additions & 4 deletions ui2/src/features/custom-fields/components/EditCustomFieldModal.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import type {CustomFieldDataType} from "@/types"
import type {CurrencyType, CustomFieldDataType} from "@/types"
import {
Button,
Group,
Loader,
LoadingOverlay,
Modal,
NativeSelect,
Select,
TextInput
} from "@mantine/core"
import {useEffect, useState} from "react"

import {CUSTOM_FIELD_DATA_TYPES} from "@/cconstants"
import {CURRENCIES, CUSTOM_FIELD_DATA_TYPES} from "@/cconstants"
import {
useEditCustomFieldMutation,
useGetCustomFieldQuery
Expand All @@ -29,6 +30,8 @@ export default function EditGroupModal({
onCancel,
opened
}: Args) {
const [showCurrency, setShowCurrency] = useState<boolean>(false)
const [currency, setCurrency] = useState<CurrencyType>("EUR")
const {data, isLoading} = useGetCustomFieldQuery(customFieldId)
const [updateCustomField, {isLoading: isLoadingGroupUpdate}] =
useEditCustomFieldMutation()
Expand All @@ -48,11 +51,19 @@ export default function EditGroupModal({
}

const onLocalSubmit = async () => {
const updatedData = {
let extra_data: string | undefined

if (dataType == "monetary") {
extra_data = JSON.stringify({currency: currency})
}

let updatedData = {
id: customFieldId,
name: name,
data_type: dataType
data_type: dataType,
extra_data: extra_data
}

await updateCustomField(updatedData)
formReset()
onSubmit()
Expand All @@ -63,6 +74,10 @@ export default function EditGroupModal({
onCancel()
}

const onCurrencyChange = (value: string | null) => {
setCurrency(value as CurrencyType)
}

return (
<Modal
title={"Edit Custom Field"}
Expand Down Expand Up @@ -90,6 +105,16 @@ export default function EditGroupModal({
setDataType(e.currentTarget.value as CustomFieldDataType)
}
/>
{dataType == "monetary" && (
<Select
mt="sm"
searchable
label="Currency"
value={currency}
data={CURRENCIES}
onChange={onCurrencyChange}
/>
)}

<Group justify="space-between" mt="md">
<Button variant="default" onClick={onLocalCancel}>
Expand Down
14 changes: 14 additions & 0 deletions ui2/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,17 @@ export type DocumentCustomFieldValue = {
this value is associated with */
field_id?: string
}

export type CurrencyType =
| "CHF"
| "CZK"
| "DKK"
| "EUR"
| "GBP"
| "HUF"
| "ISK"
| "NOK"
| "USD"
| "RON"
| "RUB"
| "SEK"

0 comments on commit 927c87e

Please sign in to comment.