Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | import Button from 'antd/lib/button'; import Form from 'antd/lib/form'; import { FormComponentProps } from 'antd/lib/form/Form'; import Icon from 'antd/lib/icon'; import Input from 'antd/lib/input'; import message from 'antd/lib/message'; import Modal from 'antd/lib/modal'; import Radio from 'antd/lib/radio'; import Upload from 'antd/lib/upload'; import { UploadFile } from 'antd/lib/upload/interface'; import * as React from 'react'; import { ArticleTypes } from '../../../../../shared/ArticleTypes'; import { useBoolean, useFile } from '../../../../customHooks'; import ReactQuill from '../../../components/ReactQuill'; import RULES from '../../../form/rules'; import SelectArticleCategory from './SelectArticleCategory'; interface IProps extends FormComponentProps { createArticle: any; loading: boolean; username: string; userSub: string; } const CreateArticleForm = ({ form, createArticle, loading, userSub, username, }: IProps) => { const isVisible = useBoolean(false); const isCategoryVisible = useBoolean(false); const file = useFile(); const handleTypeChange = (e: any) => { if (e.target.value === ArticleTypes.recenze) { isCategoryVisible.setTrue(); } else { isCategoryVisible.setFalse(); } }; const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); form.validateFieldsAndScroll(async (err: any, values: any) => { if (!err) { try { const createdUser = await createArticle({ variables: { data: { title: values.title, image: file.value, category: values.category, text: values.text, type: values.type, username, userSub, }, }, }); if (createdUser) { message.success('Článek vytvořen'); form.resetFields(); file.reset(); isVisible.setFalse(); } } catch (e) { message.error(e.message); form.resetFields(); isVisible.setFalse(); } } }); }; const handleBeforeUpload = (f: UploadFile) => { file.setValue(f); return false; }; return ( <React.Fragment> <Button icon="add" onClick={isVisible.setTrue} style={{ margin: 10 }}> Vytvořit článek </Button> <Modal title="Nový článek" visible={isVisible.value} onOk={handleSubmit} okText="Uložit" width="90%" style={{ top: 20 }} onCancel={isVisible.setFalse} confirmLoading={loading} destroyOnClose={true} > <Form onSubmit={handleSubmit}> <Form.Item label="Název"> {form.getFieldDecorator('title', RULES.ARTICLE_TITLE)(<Input />)} </Form.Item> <Form.Item> {form.getFieldDecorator('image', RULES.ARTICLE_IMAGE)( <Upload beforeUpload={handleBeforeUpload} fileList={file.value ? [file.value] : []} > <Button> <Icon type="upload" /> Select File </Button> </Upload>, )} </Form.Item> <Form.Item label="Typ"> {form.getFieldDecorator('type', RULES.ARTICLE_TYPE)( <Radio.Group buttonStyle="solid" onChange={handleTypeChange}> <Radio.Button value={ArticleTypes.zakulisi}> Zákulisí </Radio.Button> <Radio.Button value={ArticleTypes.recenze}> Recenze </Radio.Button> <Radio.Button value={ArticleTypes.prehledy}> Přehledy </Radio.Button> </Radio.Group>, )} </Form.Item> {isCategoryVisible.value && <SelectArticleCategory form={form} />} <Form.Item label="Text"> {form.getFieldDecorator('text')(<ReactQuill />)} </Form.Item> </Form> </Modal> </React.Fragment> ); }; export default Form.create()(CreateArticleForm); |