Files
astuto/app/javascript/components/Board/NewPostForm.tsx

118 lines
2.8 KiB
TypeScript
Raw Normal View History

2019-09-02 14:32:57 +02:00
import * as React from 'react';
import I18n from 'i18n-js';
2019-09-02 14:32:57 +02:00
import Button from '../common/Button';
2024-07-12 20:38:46 +02:00
import { SmallMutedText } from '../common/CustomTexts';
2024-12-20 14:06:48 +01:00
import { MarkdownIcon } from '../common/Icons';
2019-09-02 14:32:57 +02:00
interface Props {
title: string;
description: string;
handleTitleChange(title: string): void;
handleDescriptionChange(description: string): void;
2024-07-12 20:38:46 +02:00
2019-09-02 14:32:57 +02:00
handleSubmit(e: object): void;
2024-07-12 20:38:46 +02:00
dnf1: string;
dnf2: string;
handleDnf1Change(dnf1: string): void;
handleDnf2Change(dnf2: string): void;
currentUserFullName: string;
isSubmissionAnonymous: boolean;
2019-09-02 14:32:57 +02:00
}
const NewPostForm = ({
title,
description,
handleTitleChange,
handleDescriptionChange,
2024-07-12 20:38:46 +02:00
2019-09-02 14:32:57 +02:00
handleSubmit,
2024-07-12 20:38:46 +02:00
dnf1,
dnf2,
handleDnf1Change,
handleDnf2Change,
currentUserFullName,
isSubmissionAnonymous,
2019-09-02 14:32:57 +02:00
}: Props) => (
<div className="newPostForm">
<form>
<div className="form-group">
<input
type="text"
value={title}
onChange={e => handleTitleChange(e.target.value)}
maxLength={128}
2024-07-12 20:38:46 +02:00
placeholder={I18n.t('board.new_post.title')}
2019-09-02 14:32:57 +02:00
id="postTitle"
className="form-control"
autoFocus
/>
</div>
2024-07-12 20:38:46 +02:00
{ /* Honeypot field 1 */ }
<div className="form-group form-group-dnf">
<input
type="text"
value={dnf1}
onChange={e => handleDnf1Change(e.target.value)}
maxLength={128}
placeholder="email"
autoComplete="off"
id="email"
className="form-control"
/>
</div>
{ /* Honeypot field 2 */ }
<input
type="text"
value={dnf2}
onChange={e => handleDnf2Change(e.target.value)}
maxLength={128}
placeholder="name"
autoComplete="off"
tabIndex={-1}
id="name"
className="form-control"
/>
2019-09-02 14:32:57 +02:00
<div className="form-group">
<textarea
value={description}
onChange={e => handleDescriptionChange(e.target.value)}
rows={3}
2024-07-12 20:38:46 +02:00
placeholder={I18n.t('board.new_post.description')}
2019-09-02 14:32:57 +02:00
className="form-control"
id="postDescription"
></textarea>
2024-12-20 14:06:48 +01:00
<div style={{position: 'relative', width: 0, height: 0}}>
<MarkdownIcon style={{position: 'absolute', left: '6px', top: '-28px'}} />
</div>
2019-09-02 14:32:57 +02:00
</div>
2024-07-12 20:38:46 +02:00
<Button onClick={e => handleSubmit(e)} className="submitBtn d-block mx-auto">
{I18n.t('board.new_post.submit_button')}
</Button>
2024-07-12 20:38:46 +02:00
<SmallMutedText>
{
isSubmissionAnonymous ?
I18n.t('board.new_post.anonymous_submission_help')
:
I18n.t('board.new_post.non_anonymous_submission_help', { name: currentUserFullName })
}
</SmallMutedText>
2019-09-02 14:32:57 +02:00
</form>
</div>
);
export default NewPostForm;