import { useQuery } from '@apollo/client' import { Button, Form, Input, message, Tabs } from 'antd' import { useForm } from 'antd/lib/form/Form' import Structure from 'components/structure' import { withAuth } from 'components/with.auth' import { NextPage } from 'next' import { useRouter } from 'next/router' import React, { useState } from 'react' import { useTranslation } from 'react-i18next' import { cleanInput } from '../../../../components/clean.input' import { BaseDataTab } from '../../../../components/user/admin/base.data.tab' import { useUserUpdateMutation } from '../../../../graphql/mutation/user.update.mutation' import { ADMIN_USER_QUERY, AdminUserQueryData, AdminUserQueryVariables, } from '../../../../graphql/query/admin.user.query' const Index: NextPage = () => { const { t } = useTranslation() const router = useRouter() const [form] = useForm() const [saving, setSaving] = useState(false) const { data, loading } = useQuery( ADMIN_USER_QUERY, { variables: { id: router.query.id as string, }, onCompleted: (next) => { form.setFieldsValue(next) }, } ) const [update] = useUserUpdateMutation() const save = async (formData: AdminUserQueryData) => { setSaving(true) try { const next = ( await update({ variables: cleanInput(formData), }) ).data form.setFieldsValue(next) await message.success(t('user:updated')) } catch (e) { console.error('failed to save', e) await message.error(t('user:updateError')) } setSaving(false) } return ( {t('user:updateNow')} , ]} style={{ paddingTop: 0 }} >
{ // TODO process errors await message.error(t('validation:mandatoryFieldsMissing')) }} labelCol={{ xs: { span: 24 }, sm: { span: 6 }, }} wrapperCol={{ xs: { span: 24 }, sm: { span: 18 }, }} >
) } export default withAuth(Index, ['admin'])