refactor: infer types from zod validation

This commit is contained in:
Christel Westerberg
2024-04-29 09:53:54 +02:00
parent 00f30811cf
commit 49b7aa89f8
18 changed files with 418 additions and 217 deletions

View File

@@ -1,18 +1,19 @@
import {
ContactConfig,
ContactConfigField,
ContactFieldGroups,
} from "@/types/requests/contactConfig"
export function getValueFromContactConfig(
keyStrings: ContactConfigField,
keyString: string,
data: ContactConfig
): string | undefined {
const [groupName, key] = keyStrings.split(".") as [
const [groupName, key] = keyString.split(".") as [
ContactFieldGroups,
keyof ContactConfig[ContactFieldGroups],
]
const fieldGroup = data[groupName]
if (data[groupName]) {
const fieldGroup = data[groupName]
return fieldGroup[key]
return fieldGroup[key]
}
}