Files
payload/src/admin/components/views/CreateFirstUser/index.tsx
Dan Ribbens bab34d82f5 feat: add i18n to admin panel (#1326)
Co-authored-by: shikhantmaungs <shinkhantmaungs@gmail.com>
Co-authored-by: Thomas Ghysels <info@thomasg.be>
Co-authored-by: Kokutse Djoguenou <kokutse@Kokutses-MacBook-Pro.local>
Co-authored-by: Christian Gil <47041342+ChrisGV04@users.noreply.github.com>
Co-authored-by: Łukasz Rabiec <lukaszrabiec@gmail.com>
Co-authored-by: Jenny <jennifer.eberlei@gmail.com>
Co-authored-by: Hung Vu <hunghvu2017@gmail.com>
Co-authored-by: Shin Khant Maung <101539335+shinkhantmaungs@users.noreply.github.com>
Co-authored-by: Carlo Brualdi <carlo.brualdi@gmail.com>
Co-authored-by: Ariel Tonglet <ariel.tonglet@gmail.com>
Co-authored-by: Roman Ryzhikov <general+github@ya.ru>
Co-authored-by: maekoya <maekoya@stromatolite.jp>
Co-authored-by: Emilia Trollros <3m1l1a@emiliatrollros.se>
Co-authored-by: Kokutse J Djoguenou <90865585+Julesdj@users.noreply.github.com>
Co-authored-by: Mitch Dries <mitch.dries@gmail.com>

BREAKING CHANGE: If you assigned labels to collections, globals or block names, you need to update your config! Your GraphQL schema and generated Typescript interfaces may have changed. Payload no longer uses labels for code based naming. To prevent breaking changes to your GraphQL API and typescript types in your project, you can assign the below properties to match what Payload previously generated for you from labels.

On Collections
Use `graphQL.singularName`, `graphQL.pluralName` for GraphQL schema names.
Use `typescript.interface` for typescript generation name.

On Globals
Use `graphQL.name` for GraphQL Schema name.
Use `typescript.interface` for typescript generation name.

On Blocks (within Block fields)
Use `graphQL.singularName` for graphQL schema names.
2022-11-18 07:36:30 -05:00

85 lines
2.2 KiB
TypeScript

import React from 'react';
import { useTranslation } from 'react-i18next';
import { useConfig } from '../../utilities/Config';
import { useAuth } from '../../utilities/Auth';
import MinimalTemplate from '../../templates/Minimal';
import Meta from '../../utilities/Meta';
import Form from '../../forms/Form';
import RenderFields from '../../forms/RenderFields';
import fieldTypes from '../../forms/field-types';
import FormSubmit from '../../forms/Submit';
import { Props } from './types';
import { Field } from '../../../../fields/config/types';
import './index.scss';
const baseClass = 'create-first-user';
const CreateFirstUser: React.FC<Props> = (props) => {
const { setInitialized } = props;
const { setToken } = useAuth();
const {
admin: { user: userSlug }, collections, serverURL, routes: { admin, api },
} = useConfig();
const { t } = useTranslation('authentication');
const userConfig = collections.find((collection) => collection.slug === userSlug);
const onSuccess = (json) => {
if (json?.user?.token) {
setToken(json.user.token);
}
setInitialized(true);
};
const fields = [
{
name: 'email',
label: t('general:emailAddress'),
type: 'email',
required: true,
}, {
name: 'password',
label: t('general:password'),
type: 'password',
required: true,
}, {
name: 'confirm-password',
label: t('confirmPassword'),
type: 'confirmPassword',
required: true,
},
] as Field[];
return (
<MinimalTemplate className={baseClass}>
<h1>{t('general:welcome')}</h1>
<p>{t('beginCreateFirstUser')}</p>
<Meta
title={t('createFirstUser')}
description={t('createFirstUser')}
keywords={t('general:create')}
/>
<Form
onSuccess={onSuccess}
method="post"
redirect={admin}
action={`${serverURL}${api}/${userSlug}/first-register`}
validationOperation="create"
>
<RenderFields
fieldSchema={[
...fields,
...userConfig.fields,
]}
fieldTypes={fieldTypes}
/>
<FormSubmit>{t('general:create')}</FormSubmit>
</Form>
</MinimalTemplate>
);
};
export default CreateFirstUser;