|
@@ -1,8 +1,12 @@
|
|
|
-import React from 'react';
|
|
|
|
|
|
|
+import React, { useCallback } from 'react';
|
|
|
|
|
|
|
|
import { useTranslation } from 'next-i18next';
|
|
import { useTranslation } from 'next-i18next';
|
|
|
|
|
+import { useRouter } from 'next/router';
|
|
|
|
|
+
|
|
|
|
|
+import { apiv3Post } from '~/client/util/apiv3-client';
|
|
|
|
|
+
|
|
|
|
|
+import { useCurrentUser } from '../stores/context';
|
|
|
|
|
|
|
|
-import { useCsrfToken, useCurrentUser } from '../stores/context';
|
|
|
|
|
|
|
|
|
|
export type InvitedFormProps = {
|
|
export type InvitedFormProps = {
|
|
|
invitedFormUsername: string,
|
|
invitedFormUsername: string,
|
|
@@ -10,12 +14,40 @@ export type InvitedFormProps = {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const InvitedForm = (props: InvitedFormProps): JSX.Element => {
|
|
export const InvitedForm = (props: InvitedFormProps): JSX.Element => {
|
|
|
|
|
+
|
|
|
const { t } = useTranslation();
|
|
const { t } = useTranslation();
|
|
|
- const { data: csrfToken } = useCsrfToken();
|
|
|
|
|
|
|
+ const router = useRouter();
|
|
|
const { data: user } = useCurrentUser();
|
|
const { data: user } = useCurrentUser();
|
|
|
|
|
|
|
|
const { invitedFormUsername, invitedFormName } = props;
|
|
const { invitedFormUsername, invitedFormName } = props;
|
|
|
|
|
|
|
|
|
|
+ const submitHandler = useCallback(async(e) => {
|
|
|
|
|
+ e.preventDefault();
|
|
|
|
|
+
|
|
|
|
|
+ const formData = e.target.elements;
|
|
|
|
|
+
|
|
|
|
|
+ const {
|
|
|
|
|
+ 'invitedForm[name]': { value: name },
|
|
|
|
|
+ 'invitedForm[password]': { value: password },
|
|
|
|
|
+ 'invitedForm[username]': { value: username },
|
|
|
|
|
+ } = formData;
|
|
|
|
|
+
|
|
|
|
|
+ const invitedForm = {
|
|
|
|
|
+ name,
|
|
|
|
|
+ password,
|
|
|
|
|
+ username,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await apiv3Post('/invited', { invitedForm });
|
|
|
|
|
+ const { redirectTo } = res.data;
|
|
|
|
|
+ router.push(redirectTo);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ // TODO: show errors
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [router]);
|
|
|
|
|
+
|
|
|
if (user == null) {
|
|
if (user == null) {
|
|
|
return <></>;
|
|
return <></>;
|
|
|
}
|
|
}
|
|
@@ -26,7 +58,7 @@ export const InvitedForm = (props: InvitedFormProps): JSX.Element => {
|
|
|
<strong>{ t('invited.discription_heading') }</strong><br></br>
|
|
<strong>{ t('invited.discription_heading') }</strong><br></br>
|
|
|
<small>{ t('invited.discription') }</small>
|
|
<small>{ t('invited.discription') }</small>
|
|
|
</p>
|
|
</p>
|
|
|
- <form role="form" action="/invited/activateInvited" method="post" id="invited-form">
|
|
|
|
|
|
|
+ <form role="form" onSubmit={submitHandler} id="invited-form">
|
|
|
{/* Email Form */}
|
|
{/* Email Form */}
|
|
|
<div className="input-group">
|
|
<div className="input-group">
|
|
|
<div className="input-group-prepend">
|
|
<div className="input-group-prepend">
|
|
@@ -93,7 +125,6 @@ export const InvitedForm = (props: InvitedFormProps): JSX.Element => {
|
|
|
</div>
|
|
</div>
|
|
|
{/* Create Button */}
|
|
{/* Create Button */}
|
|
|
<div className="input-group justify-content-center d-flex mt-5">
|
|
<div className="input-group justify-content-center d-flex mt-5">
|
|
|
- <input type="hidden" name="_csrf" value={csrfToken} />
|
|
|
|
|
<button type="submit" className="btn btn-fill" id="register">
|
|
<button type="submit" className="btn btn-fill" id="register">
|
|
|
<div className="eff"></div>
|
|
<div className="eff"></div>
|
|
|
<span className="btn-label"><i className="icon-user-follow"></i></span>
|
|
<span className="btn-label"><i className="icon-user-follow"></i></span>
|