11import { useDataQuery } from '@dhis2/app-runtime'
22import i18n from '@dhis2/d2-i18n'
33import { CenteredContent , CircularLoader } from '@dhis2/ui'
4+ import { getInstance as getD2 } from 'd2'
45import CheckboxMaterial from 'material-ui/Checkbox'
56import React , { useState , useCallback } from 'react'
6- import { getInstance as getD2 } from 'd2'
77import settingsActions from '../settingsActions.js'
88import styles from './PeriodTypes.module.css'
99
@@ -143,7 +143,6 @@ const PeriodTypes = () => {
143143 try {
144144 const d2 = await getD2 ( )
145145 const api = d2 . Api . getApi ( )
146- const allPeriodTypes = data ?. periodTypes ?. periodTypes || [ ]
147146 const allowedPeriodTypes = data ?. dataOutputPeriodTypes || [ ]
148147 // Handle both array of strings and array of objects with name property
149148 const currentAllowedSet = new Set (
@@ -161,18 +160,21 @@ const PeriodTypes = () => {
161160
162161 // Convert set to array of objects with name property
163162 // The API expects: [{name: "Monthly"}, {name: "Quarterly"}, ...]
164- const updatedPeriodTypes = Array . from ( currentAllowedSet ) . map ( ( name ) => ( {
165- name,
166- } ) )
163+ const updatedPeriodTypes = Array . from ( currentAllowedSet ) . map (
164+ ( name ) => ( {
165+ name,
166+ } )
167+ )
167168
168169 // POST to the configuration endpoint
169- await api . post ( 'configuration/dataOutputPeriodTypes' , updatedPeriodTypes )
170+ await api . post (
171+ 'configuration/dataOutputPeriodTypes' ,
172+ updatedPeriodTypes
173+ )
170174
171175 // Refetch the data to get the updated state
172176 await refetch ( )
173- settingsActions . showSnackbarMessage (
174- i18n . t ( 'Settings updated' )
175- )
177+ settingsActions . showSnackbarMessage ( i18n . t ( 'Settings updated' ) )
176178 } catch ( err ) {
177179 console . error ( 'Failed to update period types:' , err )
178180 settingsActions . showSnackbarMessage (
@@ -212,9 +214,7 @@ const PeriodTypes = () => {
212214 // Create a Set of allowed period type names for quick lookup
213215 // Handle both array of strings and array of objects with name property
214216 const allowedSet = new Set (
215- allowedPeriodTypes . map ( ( pt ) =>
216- typeof pt === 'string' ? pt : pt . name
217- )
217+ allowedPeriodTypes . map ( ( pt ) => ( typeof pt === 'string' ? pt : pt . name ) )
218218 )
219219
220220 // Group period types by frequency
@@ -263,4 +263,4 @@ const PeriodTypes = () => {
263263 )
264264}
265265
266- export default PeriodTypes
266+ export default PeriodTypes
0 commit comments