import '@maicol07/mwc-card'; import '../WebComponents/TextField'; import {Inertia} from '@inertiajs/inertia'; import type {Cash} from 'cash-dom'; import type {VnodeDOM} from 'mithril'; import redaxios from 'redaxios'; // eslint-disable-next-line import/no-absolute-path import logoUrl from '/images/logo_completo.png'; import LoadingButton from '../Components/LoadingButton'; import Mdi from '../Components/Mdi'; import Page from '../Components/Page'; import type {ErrorResponse} from '../typings'; import { getFormData, isFormValid, showSnackbar, validatePassword } from '../utils'; export default class AdminSetupPage extends Page { loading: Cash; view() { return ( {__('OpenSTAManager')}

{__('Creazione account amministratore')}

{__( 'Inserisci le informazioni richieste per creare un nuovo account amministratore.' )}

); } oncreate(vnode: VnodeDOM) { super.oncreate(vnode); this.loading = $(this.element).find('#login-button mwc-circular-progress'); $(this.element) .find('#create-account-button') .on('click', this.onCreateAccountButtonClicked.bind(this)); } async onCreateAccountButtonClicked(event: PointerEvent) { event.preventDefault(); this.loading.show(); const form = $(this.element).find('form#new-admin'); // noinspection DuplicatedCode const password: HTMLElement | undefined = form.find('#password').get(0); const passwordConfirm: HTMLElement | undefined = form.find('#password_confirm').get(0); validatePassword(password as HTMLInputElement, passwordConfirm as HTMLInputElement); if (!isFormValid(form)) { this.loading.hide(); return; } const formData = getFormData(form); formData._token = $('meta[name="csrf-token"]').attr('content') as string; try { await redaxios.put(route('setup.admin.save'), formData); } catch (error: any) { this.loading.hide(); await showSnackbar(Object.values((error as ErrorResponse).data.errors).join(' '), false); return; } Inertia.visit('/'); await showSnackbar(__('Account creato con successo. Puoi ora accedere.')); } }