Skip to content

Commit

Permalink
Merge branch 'main' into tobbe-studio-configure-port
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Dec 15, 2023
2 parents caf2a4e + fb53f42 commit 7ce394f
Show file tree
Hide file tree
Showing 41 changed files with 255 additions and 191 deletions.
87 changes: 77 additions & 10 deletions docs/docs/toast-notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,98 @@ export default MainLayout

### Call the `toast` function

To render a toast notification, call the `toast` function or one of its methods:
To render a basic toast notification with default styles, call the `toast` function:

```jsx title="web/src/components/PostForm/PostForm.js"
// highlight-next-line
```jsx title="web/src/layouts/MainLayout/MainLayout.js"
import { toast } from '@redwoodjs/web/toast'

// ...

const PostForm = () => {
const onSubmit = () => {
const [create, { loading, error }] = useMutation(CREATE_POST_MUTATION)

const onSubmit = async (data) => {
try {
// Code to save a record...
await create({ variables: { input: data }})
// highlight-next-line
toast('Post created')
}
catch (e) {
// highlight-next-line
toast('Error creating post')
}
}

return (
// <Form onSubmit={onSubmit}> ... </Form>
)
})

export default PostForm
```

### Call the `toast` variants

To render a toast notification with default icons and default styles, call the `toast` variants:

```jsx title="web/src/components/PostForm/PostForm.js"
import { toast } from '@redwoodjs/web/toast'

// ...

const PostForm = () => {
const [create, { loading, error }] = useMutation(CREATE_POST_MUTATION, {
onCompleted: () => {
// highlight-next-line
toast('User created!')
} catch (e) {
// There's also methods for default styling:
toast.success('Post created')
}
onError: () => {
// highlight-next-line
toast.error("Error creating post...")
toast.error('Error creating post')
}
})

const onSubmit = (data) => {
create({ variables: { input: data }})
}

return (
// JSX...
// <Form onSubmit={onSubmit}> ... </Form>
)
})

export default PostForm
```

or render an async toast by calling the `toast.promise` function:

```jsx title="web/src/components/PostForm/PostForm.js"
import { toast } from '@redwoodjs/web/toast'

// ...

const PostForm = () => {
const [create, { loading, error }] = useMutation(CREATE_POST_MUTATION)

const onSubmit = (data) => {
// highlight-next-line
toast.promise(create({ variables: { input: data }}), {
loading: 'Creating post...',
success: 'Post created',
error: 'Error creating post',
})
}

return (
// <Form onSubmit={onSubmit}> ... </Form>
)
})

export default PostForm
```

:::warning

You can't use the [onError](https://www.apollographql.com/docs/react/api/react/hooks/#onerror) callback in combination with the `toast.promise` function.

:::
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@faker-js/faker": "8.0.2",
"@npmcli/arborist": "7.2.2",
"@playwright/test": "1.40.1",
"@testing-library/jest-dom": "6.1.5",
"@testing-library/jest-dom": "5.17.0",
"@testing-library/react": "14.1.2",
"@testing-library/user-event": "14.5.1",
"@types/babel__generator": "7.6.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"devDependencies": {
"@babel/cli": "7.23.4",
"@babel/core": "^7.22.20",
"@testing-library/jest-dom": "6.1.5",
"@testing-library/jest-dom": "5.17.0",
"@testing-library/react": "14.1.2",
"jest": "29.7.0",
"msw": "1.3.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/__tests__/AuthProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
configure,
} from '@testing-library/react'
import { renderHook, act } from '@testing-library/react'
import '@testing-library/jest-dom/jest-globals'
import '@testing-library/jest-dom/extend-expect'
import { graphql } from 'msw'
import { setupServer } from 'msw/node'

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@types/babel-plugin-tester": "9.0.9",
"@types/babel__core": "7.20.4",
"babel-plugin-tester": "11.0.4",
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"jest": "29.7.0"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-packages/dataMigrate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@prisma/client": "5.7.0",
"@types/fs-extra": "11.0.4",
"@types/yargs": "17.0.31",
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"fast-glob": "3.3.2",
"jest": "29.7.0",
"memfs": "4.6.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-packages/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"devDependencies": {
"@types/yargs": "17.0.31",
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"fast-glob": "3.3.2",
"jest": "29.7.0",
"typescript": "5.3.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-redwood-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@babel/core": "^7.22.20",
"@babel/plugin-transform-typescript": "^7.22.15",
"@types/babel__core": "7.20.4",
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"jest": "29.7.0",
"klaw-sync": "6.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@types/eslint": "8",
"@types/estree": "1.0.5",
"@typescript-eslint/parser": "5.62.0",
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"fast-glob": "3.3.2",
"glob": "10.3.10",
"tsx": "4.6.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/fastify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@types/aws-lambda": "8.10.126",
"@types/lodash": "4.14.201",
"@types/qs": "6.9.10",
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"typescript": "5.3.3"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
Expand Down
2 changes: 1 addition & 1 deletion packages/forms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@babel/cli": "7.23.4",
"@babel/core": "^7.22.20",
"@testing-library/dom": "9.3.3",
"@testing-library/jest-dom": "6.1.5",
"@testing-library/jest-dom": "5.17.0",
"@testing-library/react": "14.1.2",
"@testing-library/user-event": "14.5.1",
"@types/pascalcase": "1.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"chalk": "4.1.2",
"core-js": "3.34.0",
"deepmerge": "4.3.1",
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"fast-glob": "3.3.2",
"fs-extra": "11.2.0",
"graphql": "16.8.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/mailer/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"devDependencies": {
"@redwoodjs/api": "6.0.7",
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"fast-glob": "3.3.2",
"jest": "29.7.0",
"typescript": "5.3.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/mailer/handlers/in-memory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@redwoodjs/mailer-core": "6.0.7"
},
"devDependencies": {
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"fast-glob": "3.3.2",
"typescript": "5.3.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/mailer/handlers/nodemailer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"devDependencies": {
"@types/nodemailer": "6",
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"fast-glob": "3.3.2",
"typescript": "5.3.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/mailer/handlers/resend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"resend": "1.1.0"
},
"devDependencies": {
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"fast-glob": "3.3.2",
"typescript": "5.3.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/mailer/handlers/studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"devDependencies": {
"@types/nodemailer": "^6",
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"fast-glob": "3.3.2",
"typescript": "5.3.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/mailer/renderers/mjml-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"devDependencies": {
"@types/mjml": "4",
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"fast-glob": "3.3.2",
"typescript": "5.3.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/mailer/renderers/react-email/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@redwoodjs/mailer-core": "6.0.7"
},
"devDependencies": {
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"fast-glob": "3.3.2",
"typescript": "5.3.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/project-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"string-env-interpolation": "1.0.1"
},
"devDependencies": {
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"jest": "29.7.0",
"rimraf": "5.0.5",
"typescript": "5.3.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/realtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@envelop/core": "4.0.3",
"@envelop/testing": "6.0.3",
"@envelop/types": "4.0.1",
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"jest": "29.7.0",
"nodemon": "3.0.2",
"typescript": "5.3.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/record/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@babel/cli": "7.23.4",
"@babel/core": "^7.22.20",
"@prisma/internals": "5.7.0",
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"jest": "29.7.0"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
Expand Down
2 changes: 1 addition & 1 deletion packages/router/src/__tests__/location.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render } from '@testing-library/react'
import '@testing-library/jest-dom/jest-globals'
import '@testing-library/jest-dom/extend-expect'

import { LocationProvider, useLocation } from '../location'

Expand Down
2 changes: 1 addition & 1 deletion packages/router/src/__tests__/nestedSets.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react'
import type { ReactNode } from 'react'

import '@testing-library/jest-dom/jest-globals'
import '@testing-library/jest-dom/extend-expect'
import { act, render } from '@testing-library/react'

import { navigate, Route, Router } from '../'
Expand Down
2 changes: 1 addition & 1 deletion packages/router/src/__tests__/route-announcer.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'

import { render, waitFor, act } from '@testing-library/react'
import '@testing-library/jest-dom/jest-globals'
import '@testing-library/jest-dom/extend-expect'

import { getAnnouncement } from '../a11yUtils'
import { navigate } from '../history'
Expand Down
2 changes: 1 addition & 1 deletion packages/router/src/__tests__/route-focus.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render, waitFor } from '@testing-library/react'
import '@testing-library/jest-dom/jest-globals'
import '@testing-library/jest-dom/extend-expect'

import { getFocus } from '../a11yUtils'
import RouteFocus from '../route-focus'
Expand Down
2 changes: 1 addition & 1 deletion packages/router/src/__tests__/routeScrollReset.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import '@testing-library/jest-dom/jest-globals'
import '@testing-library/jest-dom/extend-expect'
import { act, cleanup, render, screen } from '@testing-library/react'

import { navigate } from '../history'
Expand Down
2 changes: 1 addition & 1 deletion packages/router/src/__tests__/router.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jest.mock('../util', () => {

import React, { useEffect, useState } from 'react'

import '@testing-library/jest-dom/jest-globals'
import '@testing-library/jest-dom/extend-expect'
import {
act,
configure,
Expand Down
2 changes: 1 addition & 1 deletion packages/router/src/__tests__/set.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react'
import type { ReactNode } from 'react'

import { act, render, waitFor } from '@testing-library/react'
import '@testing-library/jest-dom/jest-globals'
import '@testing-library/jest-dom/extend-expect'

import { navigate } from '../history'
import { Route, Router } from '../router'
Expand Down
2 changes: 1 addition & 1 deletion packages/router/src/__tests__/setContextReuse.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { act, render, waitFor } from '@testing-library/react'
import { Route, Router, navigate } from '../'
import { Set } from '../Set'

import '@testing-library/jest-dom/jest-globals'
import '@testing-library/jest-dom/extend-expect'

const HomePage = () => {
return <p>Home Page</p>
Expand Down
2 changes: 1 addition & 1 deletion packages/testing/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '@testing-library/jest-dom/jest-globals'
import '@testing-library/jest-dom/extend-expect'
import '@testing-library/jest-dom'

import { startMSW } from './src/web/mockRequests'
Expand Down
2 changes: 1 addition & 1 deletion packages/testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@redwoodjs/project-config": "6.0.7",
"@redwoodjs/router": "6.0.7",
"@redwoodjs/web": "6.0.7",
"@testing-library/jest-dom": "6.1.5",
"@testing-library/jest-dom": "5.17.0",
"@testing-library/react": "14.1.2",
"@testing-library/user-event": "14.5.1",
"@types/aws-lambda": "8.10.126",
Expand Down
2 changes: 1 addition & 1 deletion packages/tui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"stdout-update": "1.6.8"
},
"devDependencies": {
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"jest": "29.7.0",
"typescript": "5.3.3"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"devDependencies": {
"@types/yargs-parser": "21.0.3",
"esbuild": "0.19.5",
"esbuild": "0.19.9",
"typescript": "5.3.3"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
Expand Down
Loading

0 comments on commit 7ce394f

Please sign in to comment.