Skip to content

Commit

Permalink
feat: toasts dismissible
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Apr 3, 2024
1 parent 58a4d3e commit 1f5d343
Show file tree
Hide file tree
Showing 56 changed files with 478 additions and 267 deletions.
8 changes: 8 additions & 0 deletions .changeset/cuddly-tomatoes-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'explorer': minor
'hostd': minor
'renterd': minor
'walletd': minor
---

Toast notifications can now be dismissed. Closes https://github.com/SiaFoundation/web/issues/542
5 changes: 5 additions & 0 deletions .changeset/famous-donkeys-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/design-system': minor
---

Toasts can not be dismissed and now use separate title and body props.
4 changes: 2 additions & 2 deletions apps/explorer/components/Faucet/FaucetFundForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
FormFieldFormik,
FormSubmitButtonFormik,
Paragraph,
triggerToast,
triggerSuccessToast,
} from '@siafoundation/design-system'
import { toHastings } from '@siafoundation/units'
import BigNumber from 'bignumber.js'
Expand Down Expand Up @@ -50,7 +50,7 @@ export function FaucetFundForm({ onDone }: Props) {
if (response.error) {
actions.setStatus({ error: response.error })
} else {
triggerToast('Address has been funded.')
triggerSuccessToast({ title: 'Address has been funded' })
if (response.data) {
onDone(response.data.id)
}
Expand Down
6 changes: 3 additions & 3 deletions apps/explorer/components/Layout/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ConfigFields,
ControlGroup,
FieldText,
triggerToast,
triggerErrorToast,
} from '@siafoundation/design-system'
import { Search16 } from '@siafoundation/react-icons'
import React, { useCallback } from 'react'
Expand Down Expand Up @@ -51,7 +51,7 @@ export function Search() {

if (!response.data) {
form.setError('query', { message: 'Error connecting to server.' })
triggerToast('Error connecting to server.')
triggerErrorToast({ title: 'Error connecting to server' })
return
}

Expand Down Expand Up @@ -91,7 +91,7 @@ export function Search() {
form.reset()
} else {
form.setError('query', { message: 'No results match query.' })
triggerToast('No results match query.')
triggerErrorToast({ title: 'No results match query' })
}
},
[form, router, search]
Expand Down
6 changes: 4 additions & 2 deletions apps/hostd/components/Config/AnnounceButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ export function AnnounceButton() {
const response = await settingsAnnounce.post({})

if (response.error) {
triggerErrorToast('Error announcing host.')
triggerErrorToast({ title: 'Error announcing host' })
return
}
triggerSuccessToast('Successfully broadcast host announcement.')
triggerSuccessToast({
title: 'Successfully broadcast host announcement',
})
},
}),
[openConfirmDialog, settingsAnnounce, txpoolFee]
Expand Down
28 changes: 17 additions & 11 deletions apps/hostd/components/Contracts/ContractContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,25 @@ export function ContractContextMenu({
},
})
if (response.error) {
triggerErrorToast(response.error)
triggerErrorToast({
title: 'Error starting integrity check',
body: response.error,
})
} else {
triggerSuccessToast(
<>
Integrity check successfully started, depending on contract data size
this operation can take a while. Check <Code>hostd</Code>{' '}
<Link onClick={() => openDialog('alerts')}>alerts</Link> for status
updates.
</>,
{
triggerSuccessToast({
title: 'Integrity check started',
body: (
<>
Depending on contract data size this operation can take a while.
Check <Code>hostd</Code>{' '}
<Link onClick={() => openDialog('alerts')}>alerts</Link> for status
updates.
</>
),
options: {
duration: 12_000,
}
)
},
})
}
}, [id, integrityCheck, openDialog])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export function DirectoryCreate({
},
})
if (response.error) {
triggerErrorToast(`Error creating directory: ${response.error}`)
triggerErrorToast({
title: 'Error creating directory',
body: response.error,
})
} else {
onCreate(newDirName)
setNewDirName('')
Expand Down
36 changes: 18 additions & 18 deletions apps/hostd/components/Volumes/VolumeContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ export function VolumeContextMenu({ id, contentProps, buttonProps }: Props) {
},
})
if (response.error) {
triggerErrorToast(
`Error canceling volume ${getActiveOperationLabel(status)}.`
)
} else {
triggerSuccessToast(
`Successfully canceled volume ${getActiveOperationLabel(
triggerErrorToast({
title: `Error canceling volume ${getActiveOperationLabel(
status
)}.`
)
)}`,
})
} else {
triggerSuccessToast({
title: `Canceled volume ${getActiveOperationLabel(status)}`,
})
}
}}
>
Expand All @@ -100,17 +100,17 @@ export function VolumeContextMenu({ id, contentProps, buttonProps }: Props) {
},
})
if (response.error) {
triggerErrorToast(
nextReadOnly
? 'Error setting volume to read-only.'
: 'Error setting volume to read/write.'
)
triggerErrorToast({
title: nextReadOnly
? 'Error setting volume to read-only'
: 'Error setting volume to read/write',
})
} else {
triggerSuccessToast(
nextReadOnly
? 'Volume set to read-only.'
: 'Volume set to read/write.'
)
triggerSuccessToast({
title: nextReadOnly
? 'Volume set to read-only'
: 'Volume set to read/write',
})
}
}}
>
Expand Down
2 changes: 1 addition & 1 deletion apps/hostd/contexts/config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function useConfigMain() {
const revalidateAndResetForm = useCallback(async () => {
const _settings = await settings.mutate()
if (!_settings) {
triggerErrorToast('Error fetching settings.')
triggerErrorToast({ title: 'Error fetching settings' })
} else {
// also recheck dynamic dns
await dynDNSCheck.mutate()
Expand Down
18 changes: 11 additions & 7 deletions apps/hostd/contexts/config/useOnValid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,22 @@ export function useOnValid({
const needsToAnnounce =
host.data?.lastAnnouncement?.address !== values.netAddress
if (needsToAnnounce) {
triggerSuccessToast(
'Settings have been saved. Address has changed, make sure to re-announce the host.',
{
triggerSuccessToast({
title: 'Settings have been saved',
body: 'Address has changed, make sure to re-announce the host.',
options: {
duration: 20_000,
}
)
},
})
} else {
triggerSuccessToast('Settings have been saved.')
triggerSuccessToast({ title: 'Settings have been saved' })
}
await revalidateAndResetForm()
} catch (e) {
triggerErrorToast((e as Error).message)
triggerErrorToast({
title: 'Error updating settings',
body: (e as Error).message,
})
console.log(e)
}
},
Expand Down
28 changes: 16 additions & 12 deletions apps/hostd/dialogs/AlertsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ export function AlertsDialog({ open, onOpenChange }: Props) {
payload: [id],
})
if (response.error) {
triggerErrorToast('Error dismissing alert.')
triggerErrorToast({
title: 'Error dismissing alert',
body: response.error,
})
} else {
triggerSuccessToast('Alert has been dismissed.')
triggerSuccessToast({ title: 'Alert has been dismissed' })
}
},
[dismiss]
Expand All @@ -52,17 +55,18 @@ export function AlertsDialog({ open, onOpenChange }: Props) {
payload: ids,
})
if (response.error) {
triggerErrorToast(
filter
? `Error dismissing all ${filter} alerts.`
: 'Error dismissing all alerts.'
)
triggerErrorToast({
title: filter
? `Error dismissing all ${filter} alerts`
: 'Error dismissing all alerts',
body: response.error,
})
} else {
triggerSuccessToast(
filter
? `All ${filter} alerts have been dismissed.`
: 'All alerts have been dismissed.'
)
triggerSuccessToast({
title: filter
? `All ${filter} alerts have been dismissed`
: 'All alerts have been dismissed',
})
}
},
[dismiss, alerts]
Expand Down
7 changes: 5 additions & 2 deletions apps/hostd/dialogs/VolumeCreateDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,12 @@ export function VolumeCreateDialog({ trigger, open, onOpenChange }: Props) {
},
})
if (response.error) {
triggerErrorToast(response.error)
triggerErrorToast({
title: 'Error creating volume',
body: response.error,
})
} else {
triggerSuccessToast('New volume created.')
triggerSuccessToast({ title: 'New volume created' })
form.reset(defaultValues)
closeDialog()
}
Expand Down
7 changes: 5 additions & 2 deletions apps/hostd/dialogs/VolumeDeleteDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ export function VolumeDeleteDialog({ trigger, open, onOpenChange }: Props) {
},
})
if (response.error) {
triggerErrorToast(response.error)
triggerErrorToast({
title: 'Error deleting volume',
body: response.error,
})
} else {
triggerSuccessToast('Volume permanently deleted.')
triggerSuccessToast({ title: 'Volume permanently deleted' })
form.reset()
closeDialog()
}
Expand Down
7 changes: 5 additions & 2 deletions apps/hostd/dialogs/VolumeResizeDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,12 @@ export function VolumeResizeDialog({ trigger, open, onOpenChange }: Props) {
},
})
if (response.error) {
triggerErrorToast(response.error)
triggerErrorToast({
title: 'Error resizing volume',
body: response.error,
})
} else {
triggerSuccessToast('Volume resizing initiated.')
triggerSuccessToast({ title: 'Volume resizing initiated' })
form.reset(defaultValues)
closeDialog()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ export function useContractConfirmDelete() {
})

if (response.error) {
triggerErrorToast('Error deleting contract.')
triggerErrorToast({
title: 'Error deleting contract',
body: response.error,
})
}
triggerSuccessToast('Successfully deleted contract.')
triggerSuccessToast({ title: 'Deleted contract' })
},
}),
[openConfirmDialog, deleteContract]
Expand Down
32 changes: 13 additions & 19 deletions apps/renterd/components/Files/FileContextMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ import {
DropdownMenuLeftSlot,
DropdownMenuLabel,
copyToClipboardCustom,
Text,
Code,
} from '@siafoundation/design-system'
import {
Download16,
Copy16,
Delete16,
Document16,
Warning16,
Filter16,
Edit16,
Warning24,
} from '@siafoundation/react-icons'
import { useFileDelete } from '../useFileDelete'
import { CopyMetadataMenuItem } from './CopyMetadataMenuItem'
Expand Down Expand Up @@ -110,25 +109,20 @@ export function FileContextMenu({ path }: Props) {
</DropdownMenuItem>
<DropdownMenuItem
onSelect={() => {
copyToClipboardCustom(
getFileUrl(path, true),
<div className="flex flex-col gap-2">
<Text>Copied authenticated file URL to clipboard.</Text>
<Text>
copyToClipboardCustom({
text: getFileUrl(path, true),
title: 'Copied authenticated file URL to clipboard',
body: (
<>
The authenticated URL contains the <Code>renterd</Code>{' '}
password, be careful when pasting or sharing the URL.
</Text>
</div>,
{
icon: (
<div className="!flex-none w-5">
<Warning16 className="w-5 text-amber-600" />
</div>
),
duration: 10_000,
className: '!max-w-[1200px]',
}
)
</>
),
icon: <Warning24 className="text-amber-600" />,
options: {
duration: 100_000,
},
})
}}
>
<DropdownMenuLeftSlot>
Expand Down
7 changes: 5 additions & 2 deletions apps/renterd/components/Files/useDirectoryDelete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ export function useDirectoryDelete() {
})

if (response.error) {
triggerErrorToast('Error deleting directory.')
triggerErrorToast({
title: 'Error deleting directory',
body: response.error,
})
}
triggerSuccessToast('Successfully deleted directory.')
triggerSuccessToast({ title: 'Deleted directory' })
},
}),
[openConfirmDialog, deleteObject]
Expand Down
Loading

0 comments on commit 1f5d343

Please sign in to comment.