-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60c6ed6
commit b7720ba
Showing
5 changed files
with
1,572 additions
and
1,241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from 'react'; | ||
import {useMutation} from 'react-query'; | ||
import Typography from '@mui/material/Typography'; | ||
import Button from '@mui/material/Button'; | ||
import {Container} from '../components/Container'; | ||
|
||
const useRequestCapabilities = (capabilities: string[]) => { | ||
return useMutation<void, Error>('requestCapabilities', async () => { | ||
const response = await fetch('/request-capabilities', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
capabilities: capabilities, | ||
}), | ||
}); | ||
if (!response.ok) { | ||
const json = await response.json(); | ||
throw new Error(json?.error ?? 'An error ocurred, please try again.'); | ||
} | ||
}); | ||
}; | ||
|
||
type RequestCapabilitiesProps = { | ||
capabilities: any; | ||
title: string; | ||
description: string; | ||
onSuccess: () => void; | ||
}; | ||
|
||
export const RequestCapabilities = ({ | ||
title, | ||
description, | ||
capabilities, | ||
onSuccess, | ||
}: RequestCapabilitiesProps) => { | ||
const {mutate} = useRequestCapabilities(capabilities); | ||
|
||
return ( | ||
<Container sx={{alignItems: 'center', gap: 4, marginBottom: 2}}> | ||
<Typography | ||
variant="h5" | ||
sx={{ | ||
textAlign: 'center', | ||
}} | ||
> | ||
{title} | ||
</Typography> | ||
<Typography | ||
variant="h6" | ||
sx={{ | ||
textAlign: 'center', | ||
}} | ||
> | ||
{description} | ||
</Typography> | ||
<Button | ||
type="submit" | ||
variant="contained" | ||
sx={{ | ||
fontWeight: 700, | ||
}} | ||
onClick={async () => { | ||
await mutate(); | ||
onSuccess(); | ||
}} | ||
> | ||
Enable | ||
</Button> | ||
</Container> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.