diff --git a/worklenz-frontend/src/api/holiday/holiday.api.service.ts b/worklenz-frontend/src/api/holiday/holiday.api.service.ts index 7d09279a..b4da9ce0 100644 --- a/worklenz-frontend/src/api/holiday/holiday.api.service.ts +++ b/worklenz-frontend/src/api/holiday/holiday.api.service.ts @@ -245,13 +245,15 @@ export const holidayApiService = { // Countries with states getCountriesWithStates: async (): Promise> => { - const response = await apiClient.get>( - `${API_BASE_URL}/admin-center/countries-with-states` - ); - return response.data; - - // Fallback to static data if API fails - /*const supportedCountries = [ + try { + const response = await apiClient.get>( + `${API_BASE_URL}/admin-center/countries-with-states` + ); + return response.data; + } catch (error) { + logger.error('Error fetching countries with states from API, falling back to static data', error); + // Fallback to static data if API fails + const supportedCountries = [ { code: 'AD', name: 'Andorra' }, { code: 'AE', name: 'United Arab Emirates' }, { code: 'AG', name: 'Antigua & Barbuda' }, @@ -687,10 +689,11 @@ export const holidayApiService = { { code: 'ZA', name: 'South Africa' } ]; - return { - done: true, - body: supportedCountries, - } as IServerResponse;*/ + return { + done: true, + body: supportedCountries, + } as IServerResponse; + } }, // Combined holidays (official + custom) - Database-driven approach diff --git a/worklenz-frontend/src/pages/admin-center/settings/settings.tsx b/worklenz-frontend/src/pages/admin-center/settings/settings.tsx index 2e6d4d1b..c64b00f2 100644 --- a/worklenz-frontend/src/pages/admin-center/settings/settings.tsx +++ b/worklenz-frontend/src/pages/admin-center/settings/settings.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useState, useMemo } from 'react'; import { Button, Card, @@ -46,6 +46,7 @@ const SettingsPage: React.FC = () => { const [workingHours, setWorkingHours] = useState(8); const [saving, setSaving] = useState(false); const [savingHolidays, setSavingHolidays] = useState(false); + const [selectedCountryCode, setSelectedCountryCode] = useState(undefined); const [form] = Form.useForm(); const [holidayForm] = Form.useForm(); @@ -127,6 +128,7 @@ const SettingsPage: React.FC = () => { state_code: holidaySettings.state_code, auto_sync_holidays: holidaySettings.auto_sync_holidays ?? true, }); + setSelectedCountryCode(holidaySettings.country_code); } }, [holidaySettings, holidayForm]); @@ -143,12 +145,12 @@ const SettingsPage: React.FC = () => { } }; - const getSelectedCountryStates = () => { + const selectedCountryStates = useMemo(() => { const selectedCountry = countriesWithStates.find( - country => country.code === holidayForm.getFieldValue('country_code') + country => country.code === selectedCountryCode ); return selectedCountry?.states || []; - }; + }, [countriesWithStates, selectedCountryCode]); return (
@@ -193,9 +195,13 @@ const SettingsPage: React.FC = () => { - - - + + + + + + +