-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add confirmation dialog on new election page, add loaders on button
- Loading branch information
Renu
authored and
Renu
committed
Mar 17, 2023
1 parent
cf84015
commit c0d8876
Showing
7 changed files
with
188 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { ReactNode, useState } from "react"; | ||
import Button from "@mui/material/Button"; | ||
import Dialog from "@mui/material/Dialog"; | ||
import DialogActions from "@mui/material/DialogActions"; | ||
import DialogContent from "@mui/material/DialogContent"; | ||
import DialogContentText from "@mui/material/DialogContentText"; | ||
import DialogTitle from "@mui/material/DialogTitle"; | ||
import { styled } from "@mui/material/styles"; | ||
import LoadingButton from "./LoadingButton"; | ||
|
||
|
||
interface ConfirmationDialogProps { | ||
title?: string; | ||
open: boolean; | ||
children: ReactNode; | ||
btnCancelText?: string; | ||
btnConfirmText?: string; | ||
onClose: (confirmed: boolean) => void; | ||
} | ||
|
||
export default function ConfirmationDialog({ | ||
title, | ||
children, | ||
open, | ||
btnCancelText = 'Cancel', | ||
btnConfirmText = 'Confirm', | ||
onClose, | ||
}: ConfirmationDialogProps) { | ||
|
||
const handleConfirm = async () => { | ||
await onClose(true); | ||
}; | ||
|
||
const handleCancel = async () => { | ||
onClose(false); | ||
}; | ||
|
||
const ActionButton = styled(LoadingButton) ` | ||
width: auto; | ||
border-radius: 5px; | ||
margin: 0 5px 10px 5px; | ||
` | ||
|
||
return ( | ||
<Dialog maxWidth="md" open={open} onClose={handleCancel} > | ||
<DialogTitle variant="h3"> | ||
{title} | ||
</DialogTitle> | ||
<DialogContent> | ||
{children} | ||
</DialogContent> | ||
<DialogActions> | ||
<ActionButton onClick={handleCancel} variant="outlined"> | ||
{btnCancelText} | ||
</ActionButton> | ||
<ActionButton onClick={handleConfirm} autoFocus> | ||
{btnConfirmText} | ||
</ActionButton> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
}; |
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,42 @@ | ||
import Button, { ButtonProps } from "@mui/material/Button"; | ||
import CircularProgress from "@mui/material/CircularProgress"; | ||
import React, { ReactNode, useEffect, useState } from "react"; | ||
|
||
|
||
interface LoadingButtonProps extends ButtonProps { | ||
onClick: () => Promise<void>; | ||
children: ReactNode; | ||
} | ||
|
||
export default function LoadingButton ({ onClick, children, ...props }: LoadingButtonProps) { | ||
const [isLoading, setIsLoading] = useState(false); | ||
|
||
const handleClick = async () => { | ||
setIsLoading(true); | ||
await onClick(); | ||
setIsLoading(false); | ||
}; | ||
|
||
useEffect(() => { | ||
return () => { | ||
setIsLoading(false) | ||
} | ||
}, []) | ||
|
||
return ( | ||
<div> | ||
<Button onClick={handleClick} {...props} disabled={isLoading}> | ||
{children} | ||
{isLoading && ( | ||
<CircularProgress | ||
size={30} | ||
color="primary" | ||
style={{ position: "absolute" }} | ||
/> | ||
)} | ||
</Button> | ||
|
||
</div> | ||
); | ||
}; | ||
|
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
Binary file not shown.
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"Parameters": { | ||
"DEV_ENVIRONMENT": "OSX", | ||
"UPLOAD_BUCKET": "abc-uploads-development-vadminui", | ||
"ELECTIONS_DOCUMENT_BUCKET": "abc-documents-development-vadminui" | ||
"UPLOAD_BUCKET": "abc-uploads-development-radmin", | ||
"ELECTIONS_DOCUMENT_BUCKET": "abc-documents-development-radmin" | ||
} | ||
} |
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