Skip to content

Commit

Permalink
Chore: add confirmation toast for treasury email (#487)
Browse files Browse the repository at this point in the history
* add missing tests

* add success/error toasts
  • Loading branch information
greg-adams authored Oct 11, 2024
1 parent 9cf016d commit cd2e558
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 1 addition & 2 deletions api/src/services/uploads/uploads.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,8 @@ describe('treasury report', () => {
.fn()
.mockRejectedValue(new Error('Database error'))

const result = await sendTreasuryReport()
await expect(sendTreasuryReport()).rejects.toThrow('Database error')

expect(result).toBe(false)
expect(logger.error).toHaveBeenCalledWith(
expect.any(Error),
'Error sending Treasury Report'
Expand Down
4 changes: 3 additions & 1 deletion api/src/services/uploads/uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import type {
} from 'types/graphql'
import { v4 as uuidv4 } from 'uuid'

import { RedwoodError } from '@redwoodjs/api'

import { CurrentUser } from 'src/lib/auth'
import { hasRole } from 'src/lib/auth'
import {
Expand Down Expand Up @@ -411,6 +413,6 @@ export const sendTreasuryReport: MutationResolvers['sendTreasuryReport'] =
return true
} catch (error) {
logger.error(error, 'Error sending Treasury Report')
return false
throw new RedwoodError(error.message)
}
}
9 changes: 5 additions & 4 deletions web/src/pages/Upload/UploadsPage/UploadsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { ROLES } from 'api/src/lib/constants'
import { Button, ButtonGroup } from 'react-bootstrap'
import { useAuth } from 'web/src/auth'

import { useMutation, MetaTags } from '@redwoodjs/web'
import { useMutation, Metadata } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'

import UploadsCell from 'src/components/Upload/UploadsCell'

Expand All @@ -16,10 +17,10 @@ const UploadsPage = () => {
const { hasRole } = useAuth()
const [sendTreasuryReport] = useMutation(SEND_TREASURY_REPORT, {
onCompleted: () => {
console.log('Treasury Report sent by email')
toast.success('Treasury Report has been sent')
},
onError: (error) => {
console.error('Error sending Treasury Report by email', error)
toast.error('Error sending Treasury Report by email: ' + error.message)
},
})

Expand All @@ -29,7 +30,7 @@ const UploadsPage = () => {

return (
<>
<MetaTags title="Uploads Page" description="Uploads page" />
<Metadata title="Uploads Page" description="Uploads page" />

<h2>Uploads</h2>

Expand Down

0 comments on commit cd2e558

Please sign in to comment.