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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | 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 { IArticle } from '../../../../../shared'; import { ArticleStatuses } from '../../../../../shared/ArticleStatuses'; 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 { editArticle: any; loading: boolean; article: IArticle; } const EditArticleForm = ({ form, editArticle, loading, article }: IProps) => { const isVisible = useBoolean(false); const isCategoryVisible = useBoolean(article.type === ArticleTypes.recenze); 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 data = { _id: article._id, status: ArticleStatuses.updated, title: values.title, image: file.value, category: values.category, text: values.text, type: values.type, }; const editedArticle = await editArticle({ variables: { data }, }); if (editedArticle) { message.success('Článek upraven'); 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="edit" shape="circle" onClick={isVisible.setTrue} style={{ margin: 10 }} /> <Modal title="Úprava článku" 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: RULES.ARTICLE_TITLE.rules, initialValue: article.title, })(<Input />)} </Form.Item> <Form.Item> {article.image && ( <img src={article.image} style={{ width: '50px', marginRight: '20px' }} /> )} {form.getFieldDecorator('image')( <Upload beforeUpload={handleBeforeUpload} fileList={file.value ? [file.value] : []} > <Button> <Icon type="upload" /> Vybrat obrázek </Button> </Upload>, )} </Form.Item> <Form.Item label="Typ"> {form.getFieldDecorator('type', { rules: RULES.ARTICLE_TYPE.rules, initialValue: 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} article={article} /> )} <Form.Item label="Text"> {form.getFieldDecorator('text', { initialValue: article.text })( <ReactQuill />, )} </Form.Item> </Form> </Modal> </React.Fragment> ); }; export default Form.create()(EditArticleForm); |