Skip to content

Commit

Permalink
Added toast messages to API keys
Browse files Browse the repository at this point in the history
  • Loading branch information
runely committed Jun 10, 2022
1 parent 61e55fc commit 98da7aa
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/pages/APIKeys/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { relativeDateFormat } from '@vtfk/utilities'
import { Button, Dialog, DialogBody, DialogTitle, Heading3, IconButton, Table, TextField } from '@vtfk/components'
import { toast } from 'react-toastify'
import React, { useRef, useState } from 'react'
import { isEqual } from 'lodash'
import { words as capitalizeWords } from 'capitalize'
Expand Down Expand Up @@ -71,37 +72,43 @@ export function APIKeys () {
}

const handleConfirmationOkClick = async () => {
const { _id, name } = keys[confirmationItem.index]
try {
const { _id, name } = keys[confirmationItem.index]
setConfirmationItem(null)
if (confirmationItem.action === 'delete') {
await removeKeysItem(_id)
} else if (['enable', 'disable'].includes(confirmationItem.action)) {
await updateKeysItem(_id, { enabled: confirmationItem.action === 'enable', name })
}
console.log(`Successfully ${confirmationItem.action}d key`, _id) // TODO: Add toast for success
console.log(`Successfully ${confirmationItem.action}d key`, _id)
toast.success(`Successfully ${confirmationItem.action}d key '${name}'`)
} catch (error) {
const failed = error.response?.data?.message || error.message || error
console.log(`Failed to ${confirmationItem.action} key:`, failed) // TODO: Add toast for error message
console.log(`Failed to ${confirmationItem.action} key:`, failed)
toast.error(<>{`Failed to ${confirmationItem.action} key '${name}':`}<br /><b>{failed}</b></>)
}
}

const handleNewKeyOkClick = async () => {
try {
const key = await newKeysItem(newKeyName)
console.log('Successfully added key', newKeyName) // TODO: Add toast for success
setOpenNewKeyDialog(false)
setNewKeyName('')
console.log(`Successfully added key '${newKeyName}'`)
toast.success(`Successfully added key '${newKeyName}'`)
setNewKey(key)
} catch (error) {
const failed = error.response?.data?.message || error.message || error
console.log('Failed to add key:', failed) // TODO: Add toast for error message
console.log('Failed to add key:', failed)
toast.error(<>{`Failed to add key '${newKeyName}':`}<br /><b>{failed}</b></>)
}

setOpenNewKeyDialog(false)
setNewKeyName('')
}

const copyKey = () => {
navigator.clipboard.writeText(keyRef.current.value)
setNewKey(null)
toast.info('Copied key to clipboard')
}

return (
Expand Down

1 comment on commit 98da7aa

@vercel
Copy link

@vercel vercel bot commented on 98da7aa Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

e18-web – ./

e18-web-vtfk.vercel.app
e18-web-git-main-vtfk.vercel.app
e18-web.vercel.app

Please sign in to comment.