import { DataTableRow, DataTableCell } from '@rmwc/data-table'; import { TextField } from '@rmwc/textfield'; import { Select } from '@rmwc/select'; import { Checkbox } from '@rmwc/checkbox'; import { User, UserJSON, ApiError } from '@tutorbook/model'; import React from 'react'; import Utils from '@tutorbook/utils'; import to from 'await-to-js'; import useSWR, { mutate } from 'swr'; import axios, { AxiosResponse, AxiosError } from 'axios'; import styles from './people.module.scss'; async function updateUserData(user: User): Promise { const [err, res] = await to, AxiosError>( axios.put(`/api/users/${user.id}`, user.toJSON()) ); if (err && err.response) { console.error(`[ERROR] ${err.response.data.msg}`); throw new Error(err.response.data.msg); } else if (err && err.request) { console.error('[ERROR] Search REST API did not respond:', err.request); throw new Error('Search REST API did not respond.'); } else if (err) { console.error('[ERROR] While sending request:', err); throw new Error(`While sending request: ${err.message}`); } else { const { data } = res as AxiosResponse; await mutate(`/api/users/${user.id}`, data, false); } } interface RowProps { user: User; selected: boolean; setSelected: (event: React.FormEvent) => void; onBlur: (event: React.FormEvent) => void; onChange: (event: React.FormEvent, field: string) => void; } function Row({ user, selected, setSelected, onBlur, onChange, }: RowProps): JSX.Element { return ( onChange(evt, 'name')} /> onChange(evt, 'bio')} /> onChange(evt, 'email')} type='email' /> onChange(evt, 'phone')} type='tel' /> {Utils.join(user.tutoring.subjects)} {Utils.join(user.mentoring.subjects)}