37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
|
|
import { apiFetch } from './client.js'
|
||
|
|
|
||
|
|
export function listArchetypeFieldDefinitions(entityType, archetypeKey) {
|
||
|
|
const params = new URLSearchParams({
|
||
|
|
entity_type: entityType,
|
||
|
|
archetype_key: archetypeKey,
|
||
|
|
})
|
||
|
|
return apiFetch(`/api/entity-archetypes/field-definitions?${params}`)
|
||
|
|
}
|
||
|
|
|
||
|
|
export function getInitiativeFieldDefinitions(initiativeId) {
|
||
|
|
return apiFetch(`/api/initiatives/${initiativeId}/field-definitions`)
|
||
|
|
}
|
||
|
|
|
||
|
|
export function getInitiativeFields(initiativeId) {
|
||
|
|
return apiFetch(`/api/initiatives/${initiativeId}/fields`)
|
||
|
|
}
|
||
|
|
|
||
|
|
export function patchInitiativeFields(initiativeId, fields) {
|
||
|
|
return apiFetch(`/api/initiatives/${initiativeId}/fields`, {
|
||
|
|
method: 'PATCH',
|
||
|
|
body: JSON.stringify({ fields }),
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function saveInitiativeDynamicFields(initiativeId, dynamicFields) {
|
||
|
|
if (!dynamicFields || Object.keys(dynamicFields).length === 0) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
await patchInitiativeFields(initiativeId, dynamicFields)
|
||
|
|
}
|
||
|
|
|
||
|
|
export function splitInitiativeFormPayload(payload) {
|
||
|
|
const { dynamicFields, ...core } = payload
|
||
|
|
return { core, dynamicFields: dynamicFields || {} }
|
||
|
|
}
|