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 MAX_STRING_LENGTH = 150 const truncate = (text) => { let output = text if (text && text.length > MAX_STRING_LENGTH) { output = output.substring(0, MAX_STRING_LENGTH) + '...' } return output } const jsonTruncate = (obj) => { return truncate(JSON.stringify(obj, null, 2)) } const timeTag = (datetime) => { return ( ) } const checkboxInputTag = (checked) => { return } const UsersList = ({ users }) => { const [deleteUser] = useMutation(DELETE_USER_MUTATION, { onCompleted: () => { toast.success('User deleted.') }, }) const onDeleteClick = (id) => { if (confirm('Are you sure you want to delete user ' + id + '?')) { deleteUser({ variables: { id }, refetchQueries: ['USERS'] }) } } return (
| Id | User name | Created at | Updated at | Image | Bio | ||
|---|---|---|---|---|---|---|---|
| {truncate(user.id)} | {truncate(user.userName)} | {truncate(user.email)} | {timeTag(user.createdAt)} | {timeTag(user.updatedAt)} | {truncate(user.image)} | {truncate(user.bio)} |