Skip to content

Commit 6c070f8

Browse files
authored
add ImportExportDelete to AddDevice Card
1 parent cbb182a commit 6c070f8

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

website/src/components/AddDevice.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ import AccordionDetails from '@mui/material/AccordionDetails';
3030
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
3131
import Box from '@mui/material/Box';
3232
import { Warning } from '@mui/icons-material';
33+
import { ImportExportDelete } from './ImportExportDelete';
3334

3435
interface Props {
3536
onAdd: () => void;
37+
onRefresh: () => void;
3638
}
3739

3840
export const AddDevice = observer(
@@ -158,7 +160,9 @@ export const AddDevice = observer(
158160
return (
159161
<>
160162
<Card>
161-
<CardHeader title="Add A Device" />
163+
<CardHeader title="Add A Device"
164+
action={<ImportExportDelete onRefresh={() => this.props.onRefresh()} />}
165+
/>
162166
<CardContent>
163167
<form onSubmit={this.submit}>
164168
<FormControl fullWidth>

website/src/components/Devices.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,20 @@ export const Devices = observer(
6161
);
6262
}
6363
return (
64-
<Grid container spacing={3} justifyContent="center">
65-
<Grid item xs={12}>
66-
<Grid container spacing={3}>
67-
{this.devices.current.map((device, i) => (
68-
<Grid key={i} item xs={12} sm={6} md={4} lg={3}>
69-
<DeviceListItem device={device} onRemove={() => this.devices.refresh()} />
70-
</Grid>
71-
))}
64+
<Grid container spacing={3} justifyContent="center">
65+
<Grid item xs={12}>
66+
<Grid container spacing={3}>
67+
{this.devices.current.map((device, i) => (
68+
<Grid key={i} item xs={12} sm={6} md={4} lg={3}>
69+
<DeviceListItem device={device} onRemove={() => this.devices.refresh()} />
70+
</Grid>
71+
))}
72+
</Grid>
73+
</Grid>
74+
<Grid item xs={12} sm={10} md={10} lg={6}>
75+
<AddDevice onAdd={() => this.devices.refresh()} onRefresh={() => this.devices.refresh()} />
7276
</Grid>
7377
</Grid>
74-
<Grid item xs={12} sm={10} md={10} lg={6}>
75-
<AddDevice onAdd={() => this.devices.refresh()} />
76-
</Grid>
77-
</Grid>
7878
);
7979
}
8080
},

website/src/components/ImportExportDelete.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { toast } from './Toast';
1111
import { confirm } from './Present';
1212

1313

14-
export function ImportExportDelete() {
14+
export function ImportExportDelete({ onRefresh }: { onRefresh?: () => void }) {
1515
const handleExport = async () => {
1616
try {
1717
const response = await grpc.devices.listDevices({});
@@ -54,7 +54,8 @@ export function ImportExportDelete() {
5454
});
5555
}
5656

57-
toast({ text: 'Devices imported successfully', intent: 'success' });
57+
toast({ text: 'Devices imported successfully', intent: 'success' });
58+
if (onRefresh) onRefresh();
5859
} catch (error) {
5960
toast({ text: 'Failed to import devices: ' + (error as Error).message, intent: 'error' });
6061
}
@@ -72,7 +73,8 @@ export function ImportExportDelete() {
7273
});
7374
}
7475

75-
toast({ text: 'All devices deleted successfully', intent: 'success' });
76+
toast({ text: 'All devices deleted successfully', intent: 'success' });
77+
if (onRefresh) onRefresh();
7678
} catch (error) {
7779
toast({ text: 'Failed to delete devices: ' + (error as Error).message, intent: 'error' });
7880
}

0 commit comments

Comments
 (0)