Application adding bugfix; consolidated Settings headers
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Divider,
|
||||
Grid,
|
||||
GridCol,
|
||||
Group,
|
||||
Modal,
|
||||
Popover,
|
||||
Stack,
|
||||
TextInput,
|
||||
@@ -13,29 +11,36 @@ import {
|
||||
import { useDebouncedValue, useDisclosure } from '@mantine/hooks';
|
||||
import { useCommonHooks, useMutationAPI, useQueryAPI } from 'hooks';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { cardClasses, modalClasses, textInputClasses } from 'styles';
|
||||
import { textInputClasses } from 'styles';
|
||||
import type { WolClient } from 'types';
|
||||
import AddItemModal from '../Shared/AddItemModal';
|
||||
import SettingsHeader from '../Shared/SettingsHeader';
|
||||
import DebouncedWolClient from './DebouncedWolClient';
|
||||
import WolClientSettingsItem from './WolClientSettingsItem';
|
||||
|
||||
const WolClientSettings = () => {
|
||||
const defaultWolClient: WolClient = {
|
||||
id: undefined,
|
||||
hostname: '',
|
||||
macAddress: '',
|
||||
};
|
||||
const endpoint = 'api/wolClients';
|
||||
const { data: wolClientsData, isFetched: wolClientsIsFetched } = useQueryAPI({
|
||||
endpoint: endpoint,
|
||||
});
|
||||
const [wolClients, setWolClients] = useState<WolClient[]>([]);
|
||||
const { mutateAsync } = useMutationAPI();
|
||||
const { isMobile, modalStyle } = useCommonHooks();
|
||||
const [newWolClient, setNewWolClient] = useState<WolClient>({
|
||||
id: undefined,
|
||||
hostname: '',
|
||||
macAddress: '',
|
||||
});
|
||||
const { isMobile } = useCommonHooks();
|
||||
const [newWolClient, setNewWolClient] = useState<WolClient>(defaultWolClient);
|
||||
const [modalOpened, { open: openModal, close: closeModal }] = useDisclosure(false);
|
||||
const [searchValue, setSearchValue] = useState('');
|
||||
const [debouncedSearch] = useDebouncedValue(searchValue, 500);
|
||||
|
||||
const handleClose = () => {
|
||||
setNewWolClient(defaultWolClient);
|
||||
closeModal();
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (wolClientsData && wolClientsIsFetched) {
|
||||
setWolClients(
|
||||
@@ -48,93 +53,75 @@ const WolClientSettings = () => {
|
||||
|
||||
return (
|
||||
<Stack>
|
||||
<Modal.Root
|
||||
size={'60%'}
|
||||
className={modalClasses.helpModal}
|
||||
classNames={modalClasses}
|
||||
opened={modalOpened}
|
||||
fullScreen={isMobile}
|
||||
onClose={() => {
|
||||
closeModal();
|
||||
}}
|
||||
style={modalStyle}
|
||||
closeOnEscape
|
||||
closeOnClickOutside
|
||||
>
|
||||
<Modal.Overlay />
|
||||
<Modal.Content>
|
||||
<Modal.Header>
|
||||
<Modal.Title>Add a new WoL Client</Modal.Title>
|
||||
<Modal.CloseButton />
|
||||
</Modal.Header>
|
||||
<Modal.Body pb={'2rem'}>
|
||||
<Card className={cardClasses.settingsItem} classNames={cardClasses}>
|
||||
<Stack gap={0} w={'100%'} align='center'>
|
||||
<Group w={'100%'} justify='center'>
|
||||
<TextInput
|
||||
label={'Hostname'}
|
||||
className={textInputClasses.settingsItem}
|
||||
pt={16}
|
||||
classNames={textInputClasses}
|
||||
defaultValue={newWolClient.hostname}
|
||||
onChange={(event) => {
|
||||
setNewWolClient({
|
||||
...newWolClient,
|
||||
hostname: event.target.value,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<TextInput
|
||||
label={'MAC Address'}
|
||||
className={textInputClasses.settingsItem}
|
||||
pt={16}
|
||||
classNames={textInputClasses}
|
||||
defaultValue={newWolClient.macAddress}
|
||||
onChange={(event) => {
|
||||
setNewWolClient({
|
||||
...newWolClient,
|
||||
macAddress: event.target.value,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</Group>
|
||||
<Divider color='black' my='lg' />
|
||||
<Group pos={'absolute'} bottom={8}>
|
||||
<Button
|
||||
color={'green'}
|
||||
styles={{ label: { color: 'black' } }}
|
||||
onClick={() => {
|
||||
if (newWolClient) {
|
||||
mutateAsync({
|
||||
method: 'POST',
|
||||
endpoint: endpoint,
|
||||
body: newWolClient,
|
||||
});
|
||||
closeModal();
|
||||
}
|
||||
}}
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
<Button
|
||||
color={'red'}
|
||||
styles={{ label: { color: 'black' } }}
|
||||
onClick={() => {
|
||||
closeModal();
|
||||
}}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
</Card>
|
||||
</Modal.Body>
|
||||
</Modal.Content>
|
||||
</Modal.Root>
|
||||
<AddItemModal
|
||||
modalOpened={modalOpened}
|
||||
handleClose={handleClose}
|
||||
title={'Add a new WoL Client'}
|
||||
body={
|
||||
<Stack gap={0} w={'100%'} align='center'>
|
||||
<Group w={'100%'} justify='center'>
|
||||
<TextInput
|
||||
label={'Hostname'}
|
||||
className={textInputClasses.settingsItem}
|
||||
pt={16}
|
||||
classNames={textInputClasses}
|
||||
defaultValue={newWolClient.hostname}
|
||||
onChange={(event) => {
|
||||
setNewWolClient({
|
||||
...newWolClient,
|
||||
hostname: event.target.value,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<TextInput
|
||||
label={'MAC Address'}
|
||||
className={textInputClasses.settingsItem}
|
||||
pt={16}
|
||||
classNames={textInputClasses}
|
||||
defaultValue={newWolClient.macAddress}
|
||||
onChange={(event) => {
|
||||
setNewWolClient({
|
||||
...newWolClient,
|
||||
macAddress: event.target.value,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</Group>
|
||||
<Divider color='black' my='lg' />
|
||||
<Group pos={'absolute'} bottom={8}>
|
||||
<Button
|
||||
color={'green'}
|
||||
styles={{ label: { color: 'black' } }}
|
||||
onClick={() => {
|
||||
if (newWolClient) {
|
||||
mutateAsync({
|
||||
method: 'POST',
|
||||
endpoint: endpoint,
|
||||
body: newWolClient,
|
||||
});
|
||||
closeModal();
|
||||
}
|
||||
}}
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
<Button
|
||||
color={'red'}
|
||||
styles={{ label: { color: 'black' } }}
|
||||
onClick={() => {
|
||||
closeModal();
|
||||
}}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
}
|
||||
/>
|
||||
<SettingsHeader
|
||||
setDragging={undefined}
|
||||
openModal={openModal}
|
||||
title={'Search Providers'}
|
||||
title={'WoL Clients'}
|
||||
tooltip={{
|
||||
title: 'Wake on Lan clients can be configured here.',
|
||||
highlightList: ['Clients', 'homepage'],
|
||||
|
||||
Reference in New Issue
Block a user