Skip to content

Commit

Permalink
Merge 9247dff into b0de879
Browse files Browse the repository at this point in the history
  • Loading branch information
cannikin authored Mar 8, 2021
2 parents b0de879 + 9247dff commit 6f317f7
Show file tree
Hide file tree
Showing 29 changed files with 96 additions and 483 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
.rw-scaffold ::after,
.rw-scaffold ::before {
box-sizing: inherit;
border-width: 0;
border-style: solid;
border-color: #e2e8f0;
}
.rw-scaffold main {
color: #4a5568;
Expand Down Expand Up @@ -102,35 +99,6 @@
color: #1a202c;
text-decoration: underline;
}
.rw-flash-message {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin: 0 1rem;
padding: 1rem;
background: #e2e8f0;
border-radius: 0.25rem;
}
.rw-flash-message .rw-flash-message-dismiss {
font-size: 1.25rem;
font-weight: 600;
line-height: 1;
margin-right: 0.25rem;
transform-origin: center;
transform: rotate(45deg);
cursor: pointer;
}
.rw-flash-message .rw-flash-message-dismiss:hover {
opacity: 0.7;
}
.rw-flash-message.rw-flash-success {
background: #48bb78;
color: #fff;
}
.rw-flash-message.rw-flash-error {
background: #e53e3e;
color: #fff;
}
.rw-form-wrapper {
box-sizing: border-box;
font-size: 0.875rem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useMutation, useFlash } from '@redwoodjs/web'
import { useMutation } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'
import { navigate, routes } from '@redwoodjs/router'
import PostForm from 'src/components/PostForm'

Expand Down Expand Up @@ -40,11 +41,10 @@ const UPDATE_POST_MUTATION = gql`
export const Loading = () => <div>Loading...</div>

export const Success = ({ post }) => {
const { addMessage } = useFlash()
const [updatePost, { loading, error }] = useMutation(UPDATE_POST_MUTATION, {
onCompleted: () => {
toast.success('Post updated')
navigate(routes.posts())
addMessage('Post updated.', { classes: 'rw-flash-success' })
},
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useMutation, useFlash } from '@redwoodjs/web'
import { useMutation } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'
import { navigate, routes } from '@redwoodjs/router'
import UserProfileForm from 'src/components/UserProfileForm'

Expand Down Expand Up @@ -27,13 +28,12 @@ const UPDATE_USER_PROFILE_MUTATION = gql`
export const Loading = () => <div>Loading...</div>

export const Success = ({ userProfile }) => {
const { addMessage } = useFlash()
const [updateUserProfile, { loading, error }] = useMutation(
UPDATE_USER_PROFILE_MUTATION,
{
onCompleted: () => {
toast.success('UserProfile updated')
navigate(routes.userProfiles())
addMessage('UserProfile updated.', { classes: 'rw-flash-success' })
},
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useMutation, useFlash } from '@redwoodjs/web'
import { useMutation } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'
import { navigate, routes } from '@redwoodjs/router'
import UserProfileForm from 'src/components/UserProfileForm'

Expand All @@ -13,13 +14,12 @@ const CREATE_USER_PROFILE_MUTATION = gql`
`

const NewUserProfile = () => {
const { addMessage } = useFlash()
const [createUserProfile, { loading, error }] = useMutation(
CREATE_USER_PROFILE_MUTATION,
{
onCompleted: () => {
toast.success('UserProfile created')
navigate(routes.userProfiles())
addMessage('UserProfile created.', { classes: 'rw-flash-success' })
},
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useMutation, useFlash } from '@redwoodjs/web'
import { useMutation } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'
import { Link, routes } from '@redwoodjs/router'

import { QUERY } from 'src/components/PostsCell'
Expand Down Expand Up @@ -38,10 +39,9 @@ const checkboxInputTag = (checked) => {
}

const PostsList = ({ posts }) => {
const { addMessage } = useFlash()
const [deletePost] = useMutation(DELETE_POST_MUTATION, {
onCompleted: () => {
addMessage('Post deleted.', { classes: 'rw-flash-success' })
toast.success('Post deleted')
},
// This refetches the query on the list page. Read more about other ways to
// update the cache over here:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useMutation, useFlash } from '@redwoodjs/web'
import { useMutation } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'
import { navigate, routes } from '@redwoodjs/router'
import PostForm from 'src/components/PostForm'

Expand All @@ -13,11 +14,10 @@ const CREATE_POST_MUTATION = gql`
`

const NewPost = () => {
const { addMessage } = useFlash()
const [createPost, { loading, error }] = useMutation(CREATE_POST_MUTATION, {
onCompleted: () => {
toast.success('Post created')
navigate(routes.posts())
addMessage('Post created.', { classes: 'rw-flash-success' })
},
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useMutation, useFlash } from '@redwoodjs/web'
import { useMutation } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'
import { Link, routes, navigate } from '@redwoodjs/router'

import { QUERY } from 'src/components/PostsCell'
Expand Down Expand Up @@ -32,11 +33,10 @@ const checkboxInputTag = (checked) => {
}

const Post = ({ post }) => {
const { addMessage } = useFlash()
const [deletePost] = useMutation(DELETE_POST_MUTATION, {
onCompleted: () => {
toast.success('Post deleted')
navigate(routes.posts())
addMessage('Post deleted.', { classes: 'rw-flash-success' })
},
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Link, routes } from '@redwoodjs/router'
import { Flash } from '@redwoodjs/web'
import { Toaster } from '@redwoodjs/web/toast'

const PostsLayout = (props) => {
return (
<div className="rw-scaffold">
<Flash timeout={1000} />
<Toaster />
<header className="rw-header">
<h1 className="rw-heading rw-heading-primary">
<Link to={routes.posts()} className="rw-link">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
.rw-scaffold ::after,
.rw-scaffold ::before {
box-sizing: inherit;
border-width: 0;
border-style: solid;
border-color: #e2e8f0;
}
.rw-scaffold main {
color: #4a5568;
Expand Down Expand Up @@ -102,35 +99,6 @@
color: #1a202c;
text-decoration: underline;
}
.rw-flash-message {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin: 0 1rem;
padding: 1rem;
background: #e2e8f0;
border-radius: 0.25rem;
}
.rw-flash-message .rw-flash-message-dismiss {
font-size: 1.25rem;
font-weight: 600;
line-height: 1;
margin-right: 0.25rem;
transform-origin: center;
transform: rotate(45deg);
cursor: pointer;
}
.rw-flash-message .rw-flash-message-dismiss:hover {
opacity: 0.7;
}
.rw-flash-message.rw-flash-success {
background: #48bb78;
color: #fff;
}
.rw-flash-message.rw-flash-error {
background: #e53e3e;
color: #fff;
}
.rw-form-wrapper {
box-sizing: border-box;
font-size: 0.875rem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useMutation, useFlash } from '@redwoodjs/web'
import { useMutation } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'
import { navigate, routes } from '@redwoodjs/router'
import ${singularPascalName}Form from 'src/components/${pascalScaffoldPath}${singularPascalName}Form'

Expand All @@ -20,11 +21,10 @@ const UPDATE_${singularConstantName}_MUTATION = gql`
export const Loading = () => <div>Loading...</div>

export const Success = ({ ${singularCamelName} }) => {
const { addMessage } = useFlash()
const [update${singularPascalName}, { loading, error }] = useMutation(UPDATE_${singularConstantName}_MUTATION, {
onCompleted: () => {
toast.success('${singularPascalName} updated')
navigate(routes.${pluralRouteName}())
addMessage('${singularPascalName} updated.', { classes: 'rw-flash-success' })
},
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useMutation, useFlash } from '@redwoodjs/web'
import { useMutation } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'
import { Link, routes, navigate } from '@redwoodjs/router'

import { QUERY } from 'src/components/${pascalScaffoldPath}${pluralPascalName}Cell'
Expand Down Expand Up @@ -32,11 +33,10 @@ const checkboxInputTag = (checked) => {
}

const ${singularPascalName} = ({ ${singularCamelName} }) => {
const { addMessage } = useFlash()
const [delete${singularPascalName}] = useMutation(DELETE_${singularConstantName}_MUTATION, {
onCompleted: () => {
toast.success('${singularPascalName} deleted')
navigate(routes.${pluralRouteName}())
addMessage('${singularPascalName} deleted.', { classes: 'rw-flash-success' })
},
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useMutation, useFlash } from '@redwoodjs/web'
import { useMutation } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'
import { Link, routes } from '@redwoodjs/router'

import { QUERY } from 'src/components/${pascalScaffoldPath}${pluralPascalName}Cell'
Expand Down Expand Up @@ -38,10 +39,9 @@ const checkboxInputTag = (checked) => {
}

const ${pluralPascalName}List = ({ ${pluralCamelName} }) => {
const { addMessage } = useFlash()
const [delete${singularPascalName}] = useMutation(DELETE_${singularConstantName}_MUTATION, {
onCompleted: () => {
addMessage('${singularPascalName} deleted.', { classes: 'rw-flash-success' })
toast.success('${singularPascalName} deleted')
},
// This refetches the query on the list page. Read more about other ways to
// update the cache over here:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useMutation, useFlash } from '@redwoodjs/web'
import { useMutation } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'
import { navigate, routes } from '@redwoodjs/router'
import ${singularPascalName}Form from 'src/components/${pascalScaffoldPath}${singularPascalName}Form'

Expand All @@ -13,11 +14,10 @@ const CREATE_${singularConstantName}_MUTATION = gql`
`

const New${singularPascalName} = () => {
const { addMessage } = useFlash()
const [create${singularPascalName}, { loading, error }] = useMutation(CREATE_${singularConstantName}_MUTATION, {
onCompleted: () => {
toast.success('${singularPascalName} created')
navigate(routes.${pluralRouteName}())
addMessage('${singularPascalName} created.', { classes: 'rw-flash-success' })
},
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Link, routes } from '@redwoodjs/router'
import { Flash } from '@redwoodjs/web'
import { Toaster } from '@redwoodjs/web/toast'

const ${pluralPascalName}Layout = (props) => {
return (
<div className="rw-scaffold">
<Flash timeout={1000} />
<Toaster />
<header className="rw-header">
<h1 className="rw-heading rw-heading-primary">
<Link
Expand Down
4 changes: 3 additions & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"files": [
"dist",
"apollo",
"toast",
"src/entry"
],
"main": "./dist/index.js",
Expand All @@ -15,7 +16,8 @@
"@redwoodjs/auth": "^0.26.2",
"core-js": "3.6.5",
"graphql": "^15.3.0",
"proptypes": "^1.1.0"
"proptypes": "^1.1.0",
"react-hot-toast": "^1.0.2"
},
"peerDependencies": {
"react": "^17.0.1"
Expand Down
3 changes: 1 addition & 2 deletions packages/web/src/apollo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
useFetchConfig,
} from 'src/components/FetchConfigProvider'
import { GraphQLHooksProvider } from 'src/components/GraphQLHooksProvider'
import { FlashProvider } from 'src/flash'

const ApolloProviderWithFetchConfig: React.FunctionComponent<{
config?: Omit<ApolloClientOptions<InMemoryCache>, 'cache'>
Expand Down Expand Up @@ -76,7 +75,7 @@ export const RedwoodApolloProvider: React.FunctionComponent<{
<FetchConfigProvider useAuth={useAuth}>
<ApolloProviderWithFetchConfig config={graphQLClientConfig}>
<GraphQLHooksProvider useQuery={useQuery} useMutation={useMutation}>
<FlashProvider>{children}</FlashProvider>
{children}
</GraphQLHooksProvider>
</ApolloProviderWithFetchConfig>
</FetchConfigProvider>
Expand Down
Loading

0 comments on commit 6f317f7

Please sign in to comment.