-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1907a43
commit ac7a374
Showing
24 changed files
with
1,021 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ export const QUERY = gql` | |
userId | ||
createdAt | ||
categoryId | ||
} | ||
} | ||
` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { navigate, routes } from '@redwoodjs/router' | ||
|
||
import { useMutation } from '@redwoodjs/web' | ||
import { toast } from '@redwoodjs/web/toast' | ||
|
||
import UserForm from 'src/components/User/UserForm' | ||
|
||
export const QUERY = gql` | ||
query EditUserById($id: String!) { | ||
user: user(id: $id) { | ||
id | ||
name | ||
hashedPassword | ||
salt | ||
resetToken | ||
resetTokenExpiresAt | ||
roles | ||
} | ||
} | ||
` | ||
const UPDATE_USER_MUTATION = gql` | ||
mutation UpdateUserMutation($id: String!, $input: UpdateUserInput!) { | ||
updateUser(id: $id, input: $input) { | ||
id | ||
name | ||
hashedPassword | ||
salt | ||
resetToken | ||
resetTokenExpiresAt | ||
roles | ||
} | ||
} | ||
` | ||
|
||
export const Loading = () => <div>Loading...</div> | ||
|
||
export const Failure = ({ error }) => ( | ||
<div className="rw-cell-error">{error.message}</div> | ||
) | ||
|
||
export const Success = ({ user }) => { | ||
const [updateUser, { loading, error }] = useMutation(UPDATE_USER_MUTATION, { | ||
onCompleted: () => { | ||
toast.success('User updated') | ||
navigate(routes.users()) | ||
}, | ||
onError: (error) => { | ||
toast.error(error.message) | ||
}, | ||
}) | ||
|
||
const onSave = (input, id) => { | ||
updateUser({ variables: { id, input } }) | ||
} | ||
|
||
return ( | ||
<div className="rw-segment"> | ||
<header className="rw-segment-header"> | ||
<h2 className="rw-heading rw-heading-secondary">Edit User {user.id}</h2> | ||
</header> | ||
<div className="rw-segment-main"> | ||
<UserForm user={user} onSave={onSave} error={error} loading={loading} /> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { navigate, routes } from '@redwoodjs/router' | ||
import { useMutation } from '@redwoodjs/web' | ||
import { toast } from '@redwoodjs/web/toast' | ||
|
||
import UserForm from 'src/components/User/UserForm' | ||
|
||
const CREATE_USER_MUTATION = gql` | ||
mutation CreateUserMutation($input: CreateUserInput!) { | ||
createUser(input: $input) { | ||
id | ||
} | ||
} | ||
` | ||
|
||
const NewUser = () => { | ||
const [createUser, { loading, error }] = useMutation(CREATE_USER_MUTATION, { | ||
onCompleted: () => { | ||
toast.success('User created') | ||
navigate(routes.users()) | ||
}, | ||
onError: (error) => { | ||
toast.error(error.message) | ||
}, | ||
}) | ||
|
||
const onSave = (input) => { | ||
createUser({ variables: { input } }) | ||
} | ||
|
||
return ( | ||
<div className="rw-segment"> | ||
<header className="rw-segment-header"> | ||
<h2 className="rw-heading rw-heading-secondary">New User</h2> | ||
</header> | ||
<div className="rw-segment-main"> | ||
<UserForm onSave={onSave} loading={loading} error={error} /> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default NewUser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import humanize from 'humanize-string' | ||
|
||
import { Link, routes, navigate } from '@redwoodjs/router' | ||
import { useMutation } from '@redwoodjs/web' | ||
import { toast } from '@redwoodjs/web/toast' | ||
|
||
const DELETE_USER_MUTATION = gql` | ||
mutation DeleteUserMutation($id: String!) { | ||
deleteUser(id: $id) { | ||
id | ||
} | ||
} | ||
` | ||
|
||
const formatEnum = (values) => { | ||
if (values) { | ||
if (Array.isArray(values)) { | ||
const humanizedValues = values.map((value) => humanize(value)) | ||
return humanizedValues.join(', ') | ||
} else { | ||
return humanize(values) | ||
} | ||
} | ||
} | ||
|
||
const jsonDisplay = (obj) => { | ||
return ( | ||
<pre> | ||
<code>{JSON.stringify(obj, null, 2)}</code> | ||
</pre> | ||
) | ||
} | ||
|
||
const timeTag = (datetime) => { | ||
return ( | ||
datetime && ( | ||
<time dateTime={datetime} title={datetime}> | ||
{new Date(datetime).toUTCString()} | ||
</time> | ||
) | ||
) | ||
} | ||
|
||
const checkboxInputTag = (checked) => { | ||
return <input type="checkbox" checked={checked} disabled /> | ||
} | ||
|
||
const User = ({ user }) => { | ||
const [deleteUser] = useMutation(DELETE_USER_MUTATION, { | ||
onCompleted: () => { | ||
toast.success('User deleted') | ||
navigate(routes.users()) | ||
}, | ||
onError: (error) => { | ||
toast.error(error.message) | ||
}, | ||
}) | ||
|
||
const onDeleteClick = (id) => { | ||
if (confirm('Are you sure you want to delete user ' + id + '?')) { | ||
deleteUser({ variables: { id } }) | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<div className="rw-segment"> | ||
<header className="rw-segment-header"> | ||
<h2 className="rw-heading rw-heading-secondary"> | ||
User {user.id} Detail | ||
</h2> | ||
</header> | ||
<table className="rw-table"> | ||
<tbody> | ||
<tr> | ||
<th>Id</th> | ||
<td>{user.id}</td> | ||
</tr> | ||
<tr> | ||
<th>Name</th> | ||
<td>{user.name}</td> | ||
</tr> | ||
<tr> | ||
<th>Email</th> | ||
<td>{user.email}</td> | ||
</tr> | ||
<tr> | ||
<th>Hashed password</th> | ||
<td>{user.hashedPassword}</td> | ||
</tr> | ||
<tr> | ||
<th>Salt</th> | ||
<td>{user.salt}</td> | ||
</tr> | ||
<tr> | ||
<th>Reset token</th> | ||
<td>{user.resetToken}</td> | ||
</tr> | ||
<tr> | ||
<th>Reset token expires at</th> | ||
<td>{timeTag(user.resetTokenExpiresAt)}</td> | ||
</tr> | ||
<tr> | ||
<th>Roles</th> | ||
<td>{user.roles}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
<nav className="rw-button-group"> | ||
<Link | ||
to={routes.editUser({ id: user.id })} | ||
className="rw-button rw-button-blue" | ||
> | ||
Edit | ||
</Link> | ||
<button | ||
type="button" | ||
className="rw-button rw-button-red" | ||
onClick={() => onDeleteClick(user.id)} | ||
> | ||
Delete | ||
</button> | ||
</nav> | ||
</> | ||
) | ||
} | ||
|
||
export default User |
Oops, something went wrong.