import { Box, Card, type ComboboxItem, type ComboboxLikeRenderOptionInput, Group, Select, Stack, Text, TextInput, } from '@mantine/core'; import { useDebouncedValue, useDisclosure } from '@mantine/hooks'; import { DeleteItemModal, ManagementPill } from 'components'; import { useCommonHooks, useMutationAPI } from 'hooks'; import { useEffect, useState } from 'react'; import { cardClasses, selectClasses, textClasses, textInputClasses } from 'styles'; import type { Application } from 'types'; function DebouncedApplication({ application, setIsOpen, allIcons, }: { application: Application; setIsOpen: (isOpen: boolean) => void; allIcons: any; }) { const { handleDelete, isMobile, theme } = useCommonHooks(); const [modalOpened, { open: openModal, close: closeModal }] = useDisclosure(false); const { mutateAsync } = useMutationAPI(); const [app, setApp] = useState(application); const [update, setUpdate] = useState(); const [debounced] = useDebouncedValue(update, 1000); const handleClose = () => { setIsOpen(false); closeModal(); }; useEffect(() => { if (debounced && Object.keys(debounced).length > 0) { mutateAsync({ method: 'PATCH', endpoint: 'api/applications', body: debounced }); } }, [debounced]); useEffect(() => { if (update && update !== app && Object.keys(update).length) { setApp(update); } }, [update]); return ( handleDelete(app, 'api/applications')} title='Delete Application' body={ Are you sure you want to delete this application? {`"${app.name}"`} This action cannot be undone! } /> ) => { setUpdate({ ...app, enabled: event.target.checked ? 1 : 0, }); }} openModal={openModal} /> { setUpdate({ ...app, name: event.target.value, }); }} disabled styles={ theme.textShadowsEnabled ? { label: { boxShadow: '2px 2px var(--mantine-color-border-0)' }, } : undefined } /> { setUpdate({ ...app, baseUrl: event.target.value, }); }} styles={ theme.textShadowsEnabled ? { label: { boxShadow: '2px 2px var(--mantine-color-border-0)' }, } : undefined } /> { setUpdate({ ...app, url: event.target.value, }); }} styles={ theme.textShadowsEnabled ? { label: { boxShadow: '2px 2px var(--mantine-color-border-0)' }, } : undefined } />