import { Card, Grid, GridCol, Overlay, Stack, TextInput } from '@mantine/core'; import { useDebouncedValue } from '@mantine/hooks'; import { useCommonHooks, useMutationAPI, useQueryAPI } from 'hooks'; import { useEffect, useState } from 'react'; import { cardClasses, textInputClasses } from 'styles'; import type { PersonalData } from 'types'; import SettingsHeader from '../Shared/SettingsHeader'; const PersonalizationSettings = () => { const endpoint = 'api/personalData'; const { data: personalData, isFetched: personalIsFetched, isFetching: personalIsFetching, } = useQueryAPI({ endpoint: endpoint, }); const [personal, setPersonal] = useState(); const [update, setUpdate] = useState({}); const [debounced] = useDebouncedValue(update, 1000); const { mutateAsync: editRow } = useMutationAPI(); const { isMobile } = useCommonHooks(); useEffect(() => { if (personalData && personalIsFetched) { setPersonal(personalData[0]); } }, [personalData, personalIsFetched]); useEffect(() => { if (Object.keys(debounced).length) { setPersonal(update); editRow({ method: 'PATCH', endpoint: endpoint, body: debounced }); setUpdate({}); } }, [debounced]); useEffect(() => { if (update !== personal && Object.keys(update).length) { setPersonal(update); } }, [update]); return ( {}} title={'Personalization'} tooltip={{ title: 'The personalization section allows you to update basic information.', highlightList: [ 'first name', 'last name', 'name', 'first', 'last', 'physical address', ], description: 'The first and last name fields will be used for greetings, and the physical address field will be used for weather.', }} searchValue={undefined} setSearchValue={() => {}} searchPlaceholder={undefined} /> {personalIsFetching && ( )} { const updatedPersonal = { ...personal, firstName: event.currentTarget.value, }; setUpdate(updatedPersonal); }} /> { const updatedPersonal = { ...personal, lastName: event.currentTarget.value, }; setUpdate(updatedPersonal); }} /> { const updatedPersonal = { ...personal, email: event.currentTarget.value, }; setUpdate(updatedPersonal); }} /> { const updatedPersonal = { ...personal, physicalAddress: event.currentTarget.value, }; setUpdate(updatedPersonal); }} /> ); }; export default PersonalizationSettings;