@chakra-ui/react#AlertDialogHeader TypeScript Examples
The following examples show how to use
@chakra-ui/react#AlertDialogHeader.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfirmationDialog.tsx From bluebubbles-server with Apache License 2.0 | 5 votes |
ConfirmationDialog = ({
title = 'Are you sure?',
body = 'Are you sure you want to perform this action?',
declineText = 'No',
acceptText = 'Yes',
onDecline,
onAccept,
isOpen,
modalRef,
onClose
}: ConfirmationDialogProps): JSX.Element => {
const bodyTxt = mapText(body);
return (
<AlertDialog
isOpen={isOpen}
leastDestructiveRef={modalRef}
onClose={() => onClose()}
>
<AlertDialogOverlay>
<AlertDialogContent>
<AlertDialogHeader fontSize='lg' fontWeight='bold'>
{title}
</AlertDialogHeader>
<AlertDialogBody>
{bodyTxt}
</AlertDialogBody>
<AlertDialogFooter>
{declineText ? (
<Button
ref={modalRef as React.LegacyRef<HTMLButtonElement> | undefined}
onClick={() => {
if (onDecline) onDecline();
onClose();
}}
>
{declineText}
</Button>
): null}
<Button
ml={3}
colorScheme='red'
ref={modalRef as React.LegacyRef<HTMLButtonElement> | undefined}
onClick={() => {
if (onAccept) onAccept();
onClose();
}}
>
{acceptText}
</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialogOverlay>
</AlertDialog>
);
}
Example #2
Source File: ErrorDialog.tsx From bluebubbles-server with Apache License 2.0 | 5 votes |
ErrorDialog = ({
title = 'Error!',
errorsPrefix = 'The following errors have occurred:',
errors,
closeButtonText = 'Close',
isOpen,
modalRef,
onClose
}: ErrorDialogProps): JSX.Element => {
return (
<AlertDialog
isOpen={isOpen}
leastDestructiveRef={modalRef}
onClose={() => onClose()}
>
<AlertDialogOverlay>
<AlertDialogContent>
<AlertDialogHeader fontSize='lg' fontWeight='bold'>
{title}
</AlertDialogHeader>
<AlertDialogBody>
{errorsPrefix}
<br />
<br />
<UnorderedList>
{errors.map(e => {
return <ListItem key={e.id}>{e.message}</ListItem>;
})}
</UnorderedList>
</AlertDialogBody>
<AlertDialogFooter>
<Button
ref={modalRef as React.LegacyRef<HTMLButtonElement> | undefined}
onClick={() => onClose()}
>
{closeButtonText}
</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialogOverlay>
</AlertDialog>
);
}
Example #3
Source File: Dialog.tsx From wiregui with MIT License | 5 votes |
export function Dialog({
header,
body,
isOpen,
onConfirm,
onCancel,
onClose,
motionPreset = "slideInBottom",
cancelButtonText = "Cancel",
confirmButtonText = "Confirm",
}: DialogProps) {
const cancelRef = React.useRef<HTMLButtonElement>(null);
function onHandleConfirm() {
if (onConfirm) {
onConfirm();
}
if (onClose) {
onClose();
}
}
function onHandleCancel() {
if (onCancel) {
onCancel();
}
if (onClose) {
onClose();
}
}
return (
<>
<AlertDialog
motionPreset={motionPreset}
leastDestructiveRef={cancelRef}
onClose={onClose ? onClose : () => { return; }}
isOpen={isOpen}
isCentered
>
<AlertDialogOverlay />
<AlertDialogContent bg="gray.300">
<AlertDialogHeader>{header}</AlertDialogHeader>
<AlertDialogCloseButton />
<AlertDialogBody>{body}</AlertDialogBody>
<AlertDialogFooter>
<Button ref={cancelRef} onClick={onHandleCancel}>
{cancelButtonText}
</Button>
<Button colorScheme="orange" ml={3} onClick={onHandleConfirm}>
{confirmButtonText}
</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</>
);
}
Example #4
Source File: DialogButton.tsx From wiregui with MIT License | 5 votes |
export function DialogButton({
header,
body,
onConfirm,
onCancel,
launchButtonText,
title,
color,
colorScheme,
motionPreset = "slideInBottom",
cancelButtonText = "Cancel",
confirmButtonText = "Confirm",
}: DialogButtonProps) {
const { isOpen, onOpen, onClose } = useDisclosure();
const cancelRef = React.useRef<HTMLButtonElement>(null);
function onHandleConfirm() {
if (onConfirm) {
onConfirm();
}
onClose();
}
function onHandleCancel() {
if (onCancel) {
onCancel();
}
onClose();
}
return (
<>
<Button colorScheme={colorScheme} color={color} title={title} onClick={onOpen} size="sm" ml="4">
{launchButtonText}
</Button>
<AlertDialog
motionPreset={motionPreset}
leastDestructiveRef={cancelRef}
onClose={onClose}
isOpen={isOpen}
isCentered
>
<AlertDialogOverlay />
<AlertDialogContent bg="gray.300">
<AlertDialogHeader>{header}</AlertDialogHeader>
<AlertDialogCloseButton />
<AlertDialogBody>{body}</AlertDialogBody>
<AlertDialogFooter>
<Button ref={cancelRef} onClick={onHandleCancel}>
{cancelButtonText}
</Button>
<Button colorScheme="orange" ml={3} onClick={onHandleConfirm}>
{confirmButtonText}
</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</>
);
}
Example #5
Source File: MessageDialog.tsx From ksana.in with Apache License 2.0 | 5 votes |
export function MessageDialog({
title,
message,
cancelText,
confirmText,
confirmSchema,
isOpen,
onConfirm,
onClose
}: IMessageDialogProps) {
const cancelRef = useRef<any>()
const { colorMode } = useColorMode()
return (
<AlertDialog
motionPreset="slideInBottom"
isOpen={isOpen}
leastDestructiveRef={cancelRef}
onClose={onClose}
isCentered
>
<AlertDialogOverlay>
<AlertDialogContent width="90%">
<AlertDialogHeader fontSize="lg" fontWeight="bold" color={textColor[colorMode]}>
{title}
</AlertDialogHeader>
<AlertDialogBody color={textColor[colorMode]}>{message}</AlertDialogBody>
<AlertDialogFooter>
<Button ref={cancelRef} onClick={onClose} color={textColor[colorMode]}>
{cancelText}
</Button>
{confirmText && (
<Button colorScheme={confirmSchema} onClick={onConfirm} ml={3}>
{confirmText}
</Button>
)}
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialogOverlay>
</AlertDialog>
)
}
Example #6
Source File: AddWebhookDialog.tsx From bluebubbles-server with Apache License 2.0 | 4 votes |
AddWebhookDialog = ({
onCancel,
isOpen,
modalRef,
onClose,
existingId,
}: AddWebhookDialogProps): JSX.Element => {
const [url, setUrl] = useState('');
const dispatch = useAppDispatch();
const webhooks = useAppSelector(state => state.webhookStore.webhooks) ?? [];
const [selectedEvents, setSelectedEvents] = useState(
webhookEventOptions.filter((option: any) => option.label === 'All Events') as Array<MultiSelectValue>);
const [urlError, setUrlError] = useState('');
const isUrlInvalid = (urlError ?? '').length > 0;
const [eventsError, setEventsError] = useState('');
const isEventsError = (eventsError ?? '').length > 0;
useEffect(() => {
if (!existingId) return;
const webhook = webhooks.find(e => e.id === existingId);
if (webhook) {
setUrl(webhook.url);
setSelectedEvents(convertMultiSelectValues(JSON.parse(webhook.events)));
}
}, [existingId]);
return (
<AlertDialog
isOpen={isOpen}
leastDestructiveRef={modalRef}
onClose={() => onClose()}
>
<AlertDialogOverlay>
<AlertDialogContent>
<AlertDialogHeader fontSize='lg' fontWeight='bold'>
Add a new Webhook
</AlertDialogHeader>
<AlertDialogBody>
<Text>Enter a URL to receive a POST request callback when an event occurs</Text>
<FormControl isInvalid={isUrlInvalid} mt={5}>
<FormLabel htmlFor='url'>URL</FormLabel>
<Input
id='url'
type='text'
value={url}
placeholder='https://<your URL path>'
onChange={(e) => {
setUrlError('');
setUrl(e.target.value);
}}
/>
{isUrlInvalid ? (
<FormErrorMessage>{urlError}</FormErrorMessage>
) : null}
</FormControl>
<FormControl isInvalid={isEventsError} mt={5}>
<FormLabel htmlFor='permissions'>Event Subscriptions</FormLabel>
<MultiSelect
size='md'
isMulti={true}
options={webhookEventOptions}
value={selectedEvents}
onChange={(newValues) => {
setEventsError('');
setSelectedEvents(newValues as Array<MultiSelectValue>);
}}
/>
{isEventsError ? (
<FormErrorMessage>{eventsError}</FormErrorMessage>
) : null}
</FormControl>
</AlertDialogBody>
<AlertDialogFooter>
<Button
ref={modalRef as React.LegacyRef<HTMLButtonElement> | undefined}
onClick={() => {
if (onCancel) onCancel();
setUrl('');
onClose();
}}
>
Cancel
</Button>
<Button
ml={3}
bg='brand.primary'
ref={modalRef as React.LegacyRef<HTMLButtonElement> | undefined}
onClick={() => {
if (url.length === 0) {
setUrlError('Please enter a webhook URL!');
return;
}
if (selectedEvents.length === 0) {
setEventsError('Please select at least 1 event to subscribe to!');
return;
}
if (existingId) {
dispatch(update({ id: existingId, url, events: selectedEvents }));
} else {
dispatch(create({ url, events: selectedEvents }));
}
setUrl('');
onClose();
}}
>
Save
</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialogOverlay>
</AlertDialog>
);
}
Example #7
Source File: ContactDialog.tsx From bluebubbles-server with Apache License 2.0 | 4 votes |
ContactDialog = ({
onCancel,
onDelete,
onCreate,
onUpdate,
onClose,
onAddressAdd,
onAddressDelete,
isOpen,
modalRef,
existingContact,
}: ContactDialogProps): JSX.Element => {
const [firstName, setFirstName] = useState('');
const [lastName, setLastName] = useState('');
const [displayName, setDisplayName] = useState('');
const [currentAddress, setCurrentAddress] = useState('');
const [hasEdited, setHasEdited] = useBoolean(false);
const [phones, setPhones] = useState([] as ContactAddress[]);
const [emails, setEmails] = useState([] as ContactAddress[]);
const [firstNameError, setFirstNameError] = useState('');
const isNameValid = (firstNameError ?? '').length > 0;
useEffect(() => {
if (!existingContact) return;
if (existingContact.firstName) setFirstName(existingContact.firstName);
if (existingContact.lastName) setLastName(existingContact.lastName);
if (existingContact.displayName) setDisplayName(existingContact.displayName);
if (existingContact.phoneNumbers) setPhones(existingContact.phoneNumbers);
if (existingContact.emails) setEmails(existingContact.emails);
}, [existingContact]);
const addAddress = (address: string) => {
const existsPhone = phones.map((e: ContactAddress) => e.address).includes(address);
const existsEmail = emails.map((e: ContactAddress) => e.address).includes(address);
if (existsPhone || existsEmail) {
return showErrorToast({
id: 'contacts',
description: 'Address already exists!'
});
}
if (address.includes('@')) {
setEmails([{ address }, ...emails]);
} else {
setPhones([{ address }, ...phones]);
}
if (onAddressAdd && existingContact) {
onAddressAdd(existingContact.id, address);
}
};
const removeAddress = (address: string, addressId: number | null) => {
if (address.includes('@')) {
setEmails(emails.filter((e: NodeJS.Dict<any>) => e.address !== address));
} else {
setPhones(phones.filter((e: NodeJS.Dict<any>) => e.address !== address));
}
if (onAddressDelete && addressId) {
onAddressDelete(addressId);
}
};
const _onClose = () => {
setPhones([]);
setEmails([]);
setFirstName('');
setLastName('');
setDisplayName('');
setCurrentAddress('');
setHasEdited.off();
if (onClose) onClose();
};
return (
<AlertDialog
isOpen={isOpen}
leastDestructiveRef={modalRef}
onClose={() => onClose()}
>
<AlertDialogOverlay>
<AlertDialogContent>
<AlertDialogHeader fontSize='lg' fontWeight='bold'>
{(existingContact) ? 'Edit Contact' : 'Add a new Contact'}
</AlertDialogHeader>
<AlertDialogBody>
<Text>Add a custom contact to the server's database</Text>
<FormControl isInvalid={isNameValid} mt={5}>
<FormLabel htmlFor='firstName'>First Name</FormLabel>
<Input
id='firstName'
type='text'
value={firstName}
placeholder='Tim'
onChange={(e) => {
setFirstNameError('');
setFirstName(e.target.value);
if (!hasEdited) {
setDisplayName(`${e.target.value} ${lastName}`.trim());
}
}}
/>
{isNameValid ? (
<FormErrorMessage>{firstNameError}</FormErrorMessage>
) : null}
</FormControl>
<FormControl mt={5}>
<FormLabel htmlFor='lastName'>Last Name</FormLabel>
<Input
id='lastName'
type='text'
value={lastName}
placeholder='Apple'
onChange={(e) => {
setLastName(e.target.value);
if (!hasEdited) {
setDisplayName(`${firstName} ${e.target.value}`.trim());
}
}}
/>
</FormControl>
<FormControl mt={5}>
<FormLabel htmlFor='lastName'>Display Name</FormLabel>
<Input
id='displayName'
type='text'
value={displayName}
placeholder='Tim Apple'
onChange={(e) => {
setHasEdited.on();
setDisplayName(e.target.value);
}}
/>
</FormControl>
<FormControl mt={5}>
<FormLabel htmlFor='address'>Addresses</FormLabel>
<HStack>
<Input
id='address'
type='text'
value={currentAddress}
placeholder='Add Address'
onChange={(e) => {
setCurrentAddress(e.target.value);
}}
/>
<IconButton
onClick={() => {
if (!currentAddress || currentAddress.length === 0) return;
addAddress(currentAddress);
setCurrentAddress('');
}}
aria-label='Add'
icon={<AiOutlinePlus />}
/>
</HStack>
<Flex flexDirection="row" alignItems="center" justifyContent="flex-start" flexWrap="wrap" mt={2}>
{[...phones, ...emails].map(((e: ContactAddress) => {
return (
<Tag
mt={1}
mx={1}
size={'md'}
key={e.address}
borderRadius='full'
variant='solid'
>
<TagLabel>{e.address}</TagLabel>
<TagCloseButton
onClick={() => {
removeAddress(e.address, (e.id) ? e.id : null);
}}
/>
</Tag>
);
}))}
</Flex>
</FormControl>
</AlertDialogBody>
<AlertDialogFooter>
<Button
ref={modalRef as React.LegacyRef<HTMLButtonElement> | undefined}
onClick={() => {
if (!existingContact && onCancel) onCancel();
if (existingContact && onUpdate) {
existingContact.firstName = firstName;
existingContact.lastName = lastName;
existingContact.displayName = displayName;
onUpdate(existingContact);
}
_onClose();
}}
>
{(existingContact) ? 'Save & Close' : 'Cancel'}
</Button>
{(existingContact) ? (
<Button
ml={3}
bg='red'
ref={modalRef as React.LegacyRef<HTMLButtonElement> | undefined}
onClick={() => {
if (onDelete) {
onDelete(Number.parseInt(existingContact.id));
}
_onClose();
}}
>
Delete
</Button>
) : null}
{(!existingContact) ? (
<Button
ml={3}
bg='brand.primary'
ref={modalRef as React.LegacyRef<HTMLButtonElement> | undefined}
onClick={() => {
if (firstName.length === 0) {
setFirstNameError('Please enter a first name for the contact!');
return;
}
if (onCreate) {
onCreate({
firstName,
lastName,
phoneNumbers: phones,
emails: emails,
displayName,
birthday: '',
avatar: '',
id: '',
sourceType: 'db'
});
}
_onClose();
}}
>
Create
</Button>
) : null}
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialogOverlay>
</AlertDialog>
);
}
Example #8
Source File: DynamicDnsDialog.tsx From bluebubbles-server with Apache License 2.0 | 4 votes |
DynamicDnsDialog = ({
onCancel,
onConfirm,
isOpen,
modalRef,
onClose,
port = 1234
}: DynamicDnsDialogProps): JSX.Element => {
const [address, setAddress] = useState('');
const [error, setError] = useState('');
const isInvalid = (error ?? '').length > 0;
return (
<AlertDialog
isOpen={isOpen}
leastDestructiveRef={modalRef}
onClose={() => onClose()}
>
<AlertDialogOverlay>
<AlertDialogContent>
<AlertDialogHeader fontSize='lg' fontWeight='bold'>
Set Dynamic DNS
</AlertDialogHeader>
<AlertDialogBody>
<Text>Enter your Dynamic DNS URL, including the schema and port. Here are some examples:</Text>
<br />
<UnorderedList>
<ListItem>http://thequickbrownfox.ddns.net:{port}</ListItem>
<ListItem>http://bluebubbles.no-ip.org:{port}</ListItem>
</UnorderedList>
<br />
<Text>If you plan to use your own custom certificate, please remember to use <strong>"https://"</strong> as your URL scheme</Text>
<br />
<FormControl isInvalid={isInvalid}>
<FormLabel htmlFor='address'>Dynamic DNS</FormLabel>
<Input
id='address'
type='text'
maxWidth="20em"
value={address}
placeholder={`http://<your DNS>:${port}`}
onChange={(e) => {
setError('');
setAddress(e.target.value);
}}
/>
{isInvalid ? (
<FormErrorMessage>{error}</FormErrorMessage>
) : null}
</FormControl>
</AlertDialogBody>
<AlertDialogFooter>
<Button
ref={modalRef as React.LegacyRef<HTMLButtonElement> | undefined}
onClick={() => {
if (onCancel) onCancel();
onClose();
}}
>
Cancel
</Button>
<Button
ml={3}
bg='brand.primary'
ref={modalRef as React.LegacyRef<HTMLButtonElement> | undefined}
onClick={() => {
if (address.length === 0) {
setError('Please enter a Dynamic DNS address!');
return;
}
if (onConfirm) onConfirm(address);
onClose();
}}
>
Save
</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialogOverlay>
</AlertDialog>
);
}