From 0d1802acecaa9a05749c051a59cca8c07190e64d Mon Sep 17 00:00:00 2001 From: Daxter44 Date: Tue, 13 Oct 2020 09:53:48 +0200 Subject: [PATCH 01/13] create new tag --- frontend-project/src/models/tags.ts | 14 ++++++++++++- frontend-project/src/pages/tags/new/index.tsx | 21 ++++++++++++------- frontend-project/src/services/tags.ts | 4 ++++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/frontend-project/src/models/tags.ts b/frontend-project/src/models/tags.ts index 8eb0b54f8..02e5d5ef5 100644 --- a/frontend-project/src/models/tags.ts +++ b/frontend-project/src/models/tags.ts @@ -1,4 +1,4 @@ -import { fetchAll, fetchPage } from '@/services/tags'; +import { fetchAll, fetchPage, create } from '@/services/tags'; import { Effect } from 'dva'; import { Reducer } from 'redux'; import { Tag } from '@/services/definitions'; @@ -9,6 +9,7 @@ export interface TagModelType { namespace: string; state: Tag[]; effects: { + create: Effect; fetchAll: Effect; fetchPage: Effect; }; @@ -23,6 +24,17 @@ const TagsModel: TagModelType = { namespace: 'tags', state: defaultTagsState, effects: { + *create({ payload }, { call, post }) { + const response = yield call(create, payload); + yield post({ + payload: response, + }); + // save successfully + + if (response.status === 'ok') { + console.log('zapis ok'); + } + }, *fetchAll(_, { call, put }) { const response = yield call(fetchAll); yield put({ diff --git a/frontend-project/src/pages/tags/new/index.tsx b/frontend-project/src/pages/tags/new/index.tsx index 8691ecb70..1103af8d5 100644 --- a/frontend-project/src/pages/tags/new/index.tsx +++ b/frontend-project/src/pages/tags/new/index.tsx @@ -3,9 +3,10 @@ import { Button, Col, Card, Form, Input, Row } from 'antd'; import { connect } from 'dva'; import React, { useEffect, FC } from 'react'; import { formatMessage, FormattedMessage } from 'umi-plugin-react/locale'; +import { Tag } from '@/services/definitions'; interface TagNewFormProps { - name: String; + name: string; dispatch: Function; } @@ -18,16 +19,22 @@ const tailLayout = { wrapperCol: { offset: 8, span: 16 }, }; -const TagNewForm: FC = () => { +const TagNewForm: FC = ({ dispatch }) => { const [form] = Form.useForm(); - - const onSubmit = () => { - form.submit(); + const onSubmit = (value: Tag) => { + dispatch({ + type: 'tags/create', + payload: { ...value }, + }); + }; + const onFinish = (): void => { + onSubmit(form.getFieldsValue() as Tag); }; + useEffect(() => {}, []); return ( -
+ @@ -49,7 +56,7 @@ const TagNewForm: FC = () => { - diff --git a/frontend-project/src/services/tags.ts b/frontend-project/src/services/tags.ts index fda0c1fdf..570c4d983 100644 --- a/frontend-project/src/services/tags.ts +++ b/frontend-project/src/services/tags.ts @@ -45,3 +45,7 @@ export async function fetchAll() { smallEodSDK.TagsApi(); return smallEodSDK.tagsList().then(page => fetchAllPages(page)); } +export async function create(value: Tag) { + smallEodSDK.TagsApi(); + return smallEodSDK.tagsCreate(value); +} From f21644bf2764861f78f0e4421878c1b20192a08b Mon Sep 17 00:00:00 2001 From: Daxter44 Date: Wed, 14 Oct 2020 20:27:18 +0200 Subject: [PATCH 02/13] add notification after create tag --- frontend-project/src/models/global.ts | 9 +++++++++ frontend-project/src/models/tags.ts | 15 ++++++++------- frontend-project/src/pages/tags/new/index.tsx | 7 ++----- frontend-project/src/services/tags.ts | 6 ++---- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/frontend-project/src/models/global.ts b/frontend-project/src/models/global.ts index 52ef8d50e..549a76846 100644 --- a/frontend-project/src/models/global.ts +++ b/frontend-project/src/models/global.ts @@ -1,7 +1,16 @@ +import { notification } from 'antd'; + export interface GlobalModelState { collapsed: boolean; } +export const openNotificationWithIcon = (type, msg) => { + notification[type]({ + message: msg, + description: + 'This is the content of the notification. This is the content of the notification. This is the content of the notification.', + }); +}; const GlobalModel = { namespace: 'global', diff --git a/frontend-project/src/models/tags.ts b/frontend-project/src/models/tags.ts index 02e5d5ef5..ee68612ea 100644 --- a/frontend-project/src/models/tags.ts +++ b/frontend-project/src/models/tags.ts @@ -1,7 +1,9 @@ import { fetchAll, fetchPage, create } from '@/services/tags'; import { Effect } from 'dva'; import { Reducer } from 'redux'; +import { router } from 'umi'; import { Tag } from '@/services/definitions'; +import { openNotificationWithIcon } from '@/models/global'; export type TagDefaultState = Tag[]; @@ -24,15 +26,14 @@ const TagsModel: TagModelType = { namespace: 'tags', state: defaultTagsState, effects: { - *create({ payload }, { call, post }) { + *create({ payload }, { call }) { const response = yield call(create, payload); - yield post({ - payload: response, - }); // save successfully - - if (response.status === 'ok') { - console.log('zapis ok'); + if (response.response.status === 201) { + openNotificationWithIcon('success', 'Zapis prawidlowy'); + router.replace('/tags'); + } else { + openNotificationWithIcon('error', 'Zapis nieprawidlowy'); } }, *fetchAll(_, { call, put }) { diff --git a/frontend-project/src/pages/tags/new/index.tsx b/frontend-project/src/pages/tags/new/index.tsx index 1103af8d5..174d36815 100644 --- a/frontend-project/src/pages/tags/new/index.tsx +++ b/frontend-project/src/pages/tags/new/index.tsx @@ -21,20 +21,17 @@ const tailLayout = { const TagNewForm: FC = ({ dispatch }) => { const [form] = Form.useForm(); - const onSubmit = (value: Tag) => { + const handleSubmit = (value: Tag) => { dispatch({ type: 'tags/create', payload: { ...value }, }); }; - const onFinish = (): void => { - onSubmit(form.getFieldsValue() as Tag); - }; useEffect(() => {}, []); return ( - + diff --git a/frontend-project/src/services/tags.ts b/frontend-project/src/services/tags.ts index 570c4d983..a84d4bae3 100644 --- a/frontend-project/src/services/tags.ts +++ b/frontend-project/src/services/tags.ts @@ -25,7 +25,6 @@ function fetchAllPages(page: Page) { } return page; } - export async function fetchPage({ current, pageSize, @@ -45,7 +44,6 @@ export async function fetchAll() { smallEodSDK.TagsApi(); return smallEodSDK.tagsList().then(page => fetchAllPages(page)); } -export async function create(value: Tag) { - smallEodSDK.TagsApi(); - return smallEodSDK.tagsCreate(value); +export async function create(value: Tag): Promise { + return new smallEodSDK.TagsApi().tagsCreateWithHttpInfo(value); } From 721633da5da1b968fe39956b59140c8c8fd08fc0 Mon Sep 17 00:00:00 2001 From: Adam Dobrawy Date: Wed, 14 Oct 2020 23:14:55 +0200 Subject: [PATCH 03/13] Catch SDK exception in tags create --- frontend-project/src/models/tags.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/frontend-project/src/models/tags.ts b/frontend-project/src/models/tags.ts index ee68612ea..db8e37246 100644 --- a/frontend-project/src/models/tags.ts +++ b/frontend-project/src/models/tags.ts @@ -27,13 +27,16 @@ const TagsModel: TagModelType = { state: defaultTagsState, effects: { *create({ payload }, { call }) { - const response = yield call(create, payload); - // save successfully - if (response.response.status === 201) { - openNotificationWithIcon('success', 'Zapis prawidlowy'); - router.replace('/tags'); - } else { - openNotificationWithIcon('error', 'Zapis nieprawidlowy'); + try { + const response = yield call(create, payload); + openNotificationWithIcon('success', `Zapis prawidlowy ID: ${response.id}`); + router.replace(`/tags/`); + } catch (err) { + if (err.response.status === 400 && err.response.body.name) { + err.response.body.name.forEach(message => openNotificationWithIcon('error', message)); + } else { + openNotificationWithIcon('error', err.response.body.detail); + } } }, *fetchAll(_, { call, put }) { From 9d6bb84d123807b386fe179d5fde32130ccc29ba Mon Sep 17 00:00:00 2001 From: Daxter44 Date: Thu, 15 Oct 2020 19:26:12 +0200 Subject: [PATCH 04/13] fix strings --- frontend-project/src/models/global.ts | 6 ++---- frontend-project/src/models/tags.ts | 2 +- frontend-project/src/pages/tags/new/locales/en-US.ts | 4 ++-- frontend-project/src/pages/tags/new/locales/pl-PL.ts | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/frontend-project/src/models/global.ts b/frontend-project/src/models/global.ts index 549a76846..38f612e37 100644 --- a/frontend-project/src/models/global.ts +++ b/frontend-project/src/models/global.ts @@ -6,14 +6,12 @@ export interface GlobalModelState { export const openNotificationWithIcon = (type, msg) => { notification[type]({ - message: msg, - description: - 'This is the content of the notification. This is the content of the notification. This is the content of the notification.', + message: type, + description: msg, }); }; const GlobalModel = { namespace: 'global', - state: { collapsed: false, }, diff --git a/frontend-project/src/models/tags.ts b/frontend-project/src/models/tags.ts index db8e37246..79cef0400 100644 --- a/frontend-project/src/models/tags.ts +++ b/frontend-project/src/models/tags.ts @@ -29,7 +29,7 @@ const TagsModel: TagModelType = { *create({ payload }, { call }) { try { const response = yield call(create, payload); - openNotificationWithIcon('success', `Zapis prawidlowy ID: ${response.id}`); + openNotificationWithIcon('success', `Zapis prawidlowy ID: ${response.data.id}`); router.replace(`/tags/`); } catch (err) { if (err.response.status === 400 && err.response.body.name) { diff --git a/frontend-project/src/pages/tags/new/locales/en-US.ts b/frontend-project/src/pages/tags/new/locales/en-US.ts index 4cfac3914..ba99df5d1 100644 --- a/frontend-project/src/pages/tags/new/locales/en-US.ts +++ b/frontend-project/src/pages/tags/new/locales/en-US.ts @@ -1,7 +1,7 @@ export default { 'tags-new.form.save.label': 'Save', 'tags-new.form.name.label': 'Name', - 'tags-new.form.name.placeholder': "Case's name", + 'tags-new.form.name.placeholder': "Tag's name", 'tags-new.form.name.required-error': 'Name is required', - 'tags-new.page-header-content': 'You can add new channel here.', + 'tags-new.page-header-content': 'You can add new tag here.', }; diff --git a/frontend-project/src/pages/tags/new/locales/pl-PL.ts b/frontend-project/src/pages/tags/new/locales/pl-PL.ts index 0591b9385..77cc77fef 100644 --- a/frontend-project/src/pages/tags/new/locales/pl-PL.ts +++ b/frontend-project/src/pages/tags/new/locales/pl-PL.ts @@ -3,5 +3,5 @@ export default { 'tags-new.form.name.label': 'Nazwa', 'tags-new.form.name.placeholder': 'Nazwa tagu', 'tags-new.form.name.required-error': 'Nazwa jest wymagana', - 'tags-new.page-header-content': 'Możesz dodać tutaj nowy kanał.', + 'tags-new.page-header-content': 'Możesz dodać tutaj nowy tag.', }; From 41da224a712e49e9afaf706c278b55e0c65a9022 Mon Sep 17 00:00:00 2001 From: Daxter44 Date: Thu, 15 Oct 2020 19:49:08 +0200 Subject: [PATCH 05/13] add locales to notifications --- frontend-project/src/models/tags.ts | 18 +++++++++++++++--- .../src/pages/tags/new/locales/en-US.ts | 2 ++ .../src/pages/tags/new/locales/pl-PL.ts | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/frontend-project/src/models/tags.ts b/frontend-project/src/models/tags.ts index 79cef0400..d536d9a9d 100644 --- a/frontend-project/src/models/tags.ts +++ b/frontend-project/src/models/tags.ts @@ -4,6 +4,7 @@ import { Reducer } from 'redux'; import { router } from 'umi'; import { Tag } from '@/services/definitions'; import { openNotificationWithIcon } from '@/models/global'; +import { formatMessage } from 'umi-plugin-react/locale'; export type TagDefaultState = Tag[]; @@ -29,13 +30,24 @@ const TagsModel: TagModelType = { *create({ payload }, { call }) { try { const response = yield call(create, payload); - openNotificationWithIcon('success', `Zapis prawidlowy ID: ${response.data.id}`); + openNotificationWithIcon( + 'success', + formatMessage({ id: 'tags-new.page-create-notiffy-success' }) + response.data.id, + ); router.replace(`/tags/`); } catch (err) { if (err.response.status === 400 && err.response.body.name) { - err.response.body.name.forEach(message => openNotificationWithIcon('error', message)); + err.response.body.name.forEach(message => + openNotificationWithIcon( + 'error', + formatMessage({ id: 'tags-new.page-create-notiffy-error' }) + message, + ), + ); } else { - openNotificationWithIcon('error', err.response.body.detail); + openNotificationWithIcon( + 'error', + formatMessage({ id: 'tags-new.page-create-notiffy-error' }) + err.response.body.detail, + ); } } }, diff --git a/frontend-project/src/pages/tags/new/locales/en-US.ts b/frontend-project/src/pages/tags/new/locales/en-US.ts index ba99df5d1..c8aaf081e 100644 --- a/frontend-project/src/pages/tags/new/locales/en-US.ts +++ b/frontend-project/src/pages/tags/new/locales/en-US.ts @@ -4,4 +4,6 @@ export default { 'tags-new.form.name.placeholder': "Tag's name", 'tags-new.form.name.required-error': 'Name is required', 'tags-new.page-header-content': 'You can add new tag here.', + 'tags-new.page-create-notiffy-error': 'Save error:', + 'tags-new.page-create-notiffy-success': 'Tag saved corectly ID:', }; diff --git a/frontend-project/src/pages/tags/new/locales/pl-PL.ts b/frontend-project/src/pages/tags/new/locales/pl-PL.ts index 77cc77fef..b7503db6c 100644 --- a/frontend-project/src/pages/tags/new/locales/pl-PL.ts +++ b/frontend-project/src/pages/tags/new/locales/pl-PL.ts @@ -4,4 +4,6 @@ export default { 'tags-new.form.name.placeholder': 'Nazwa tagu', 'tags-new.form.name.required-error': 'Nazwa jest wymagana', 'tags-new.page-header-content': 'Możesz dodać tutaj nowy tag.', + 'tags-new.page-create-notiffy-error': 'Zapis nieudany:', + 'tags-new.page-create-notiffy-success': 'Zapis prawidłowy ID:', }; From a698cd8994908d2b7abb6ebe541f00089c22913d Mon Sep 17 00:00:00 2001 From: Daxter44 Date: Mon, 19 Oct 2020 09:10:26 +0200 Subject: [PATCH 06/13] fix tags list path --- frontend-project/src/models/tags.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend-project/src/models/tags.ts b/frontend-project/src/models/tags.ts index d536d9a9d..5708768a4 100644 --- a/frontend-project/src/models/tags.ts +++ b/frontend-project/src/models/tags.ts @@ -34,7 +34,7 @@ const TagsModel: TagModelType = { 'success', formatMessage({ id: 'tags-new.page-create-notiffy-success' }) + response.data.id, ); - router.replace(`/tags/`); + router.replace(`/tags/list`); } catch (err) { if (err.response.status === 400 && err.response.body.name) { err.response.body.name.forEach(message => From 519fe3df20705abe5800c01f5281c7c22374f3c5 Mon Sep 17 00:00:00 2001 From: Daxter44 Date: Sun, 25 Oct 2020 09:48:48 +0100 Subject: [PATCH 07/13] improvement of comments --- frontend-project/src/models/global.ts | 8 -------- frontend-project/src/models/notification.ts | 7 +++++++ frontend-project/src/models/tags.ts | 2 +- frontend-project/src/pages/tags/new/index.tsx | 3 ++- 4 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 frontend-project/src/models/notification.ts diff --git a/frontend-project/src/models/global.ts b/frontend-project/src/models/global.ts index 38f612e37..4b7b1b3d9 100644 --- a/frontend-project/src/models/global.ts +++ b/frontend-project/src/models/global.ts @@ -1,15 +1,7 @@ -import { notification } from 'antd'; - export interface GlobalModelState { collapsed: boolean; } -export const openNotificationWithIcon = (type, msg) => { - notification[type]({ - message: type, - description: msg, - }); -}; const GlobalModel = { namespace: 'global', state: { diff --git a/frontend-project/src/models/notification.ts b/frontend-project/src/models/notification.ts new file mode 100644 index 000000000..ea019857d --- /dev/null +++ b/frontend-project/src/models/notification.ts @@ -0,0 +1,7 @@ +import { notification } from 'antd'; +import { ReactNode } from 'react'; +import { IconType } from 'antd/lib/notification'; + +export const openNotificationWithIcon = (message: IconType, description: ReactNode) => { + notification[message]({ message, description }); +}; diff --git a/frontend-project/src/models/tags.ts b/frontend-project/src/models/tags.ts index 5708768a4..0640b1a53 100644 --- a/frontend-project/src/models/tags.ts +++ b/frontend-project/src/models/tags.ts @@ -3,7 +3,7 @@ import { Effect } from 'dva'; import { Reducer } from 'redux'; import { router } from 'umi'; import { Tag } from '@/services/definitions'; -import { openNotificationWithIcon } from '@/models/global'; +import { openNotificationWithIcon } from '@/models/notification'; import { formatMessage } from 'umi-plugin-react/locale'; export type TagDefaultState = Tag[]; diff --git a/frontend-project/src/pages/tags/new/index.tsx b/frontend-project/src/pages/tags/new/index.tsx index 174d36815..4970beedb 100644 --- a/frontend-project/src/pages/tags/new/index.tsx +++ b/frontend-project/src/pages/tags/new/index.tsx @@ -1,13 +1,14 @@ import { PageHeaderWrapper } from '@ant-design/pro-layout'; import { Button, Col, Card, Form, Input, Row } from 'antd'; import { connect } from 'dva'; +import { AnyAction, Dispatch } from 'redux'; import React, { useEffect, FC } from 'react'; import { formatMessage, FormattedMessage } from 'umi-plugin-react/locale'; import { Tag } from '@/services/definitions'; interface TagNewFormProps { name: string; - dispatch: Function; + dispatch: Dispatch; } const layout = { From 510359e5eb9926f261e17546f68444c1cf30ef74 Mon Sep 17 00:00:00 2001 From: Daxter44 Date: Sun, 25 Oct 2020 10:03:41 +0100 Subject: [PATCH 08/13] improvement of comments --- frontend-project/src/models/global.ts | 8 +++++++- frontend-project/src/models/notification.ts | 7 ------- frontend-project/src/models/tags.ts | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) delete mode 100644 frontend-project/src/models/notification.ts diff --git a/frontend-project/src/models/global.ts b/frontend-project/src/models/global.ts index 4b7b1b3d9..7e85b5716 100644 --- a/frontend-project/src/models/global.ts +++ b/frontend-project/src/models/global.ts @@ -1,7 +1,13 @@ +import { notification } from 'antd'; +import { ReactNode } from 'react'; +import { IconType } from 'antd/lib/notification'; + export interface GlobalModelState { collapsed: boolean; } - +export const openNotificationWithIcon = (message: IconType, description: ReactNode) => { + notification[message]({ message, description }); +}; const GlobalModel = { namespace: 'global', state: { diff --git a/frontend-project/src/models/notification.ts b/frontend-project/src/models/notification.ts deleted file mode 100644 index ea019857d..000000000 --- a/frontend-project/src/models/notification.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { notification } from 'antd'; -import { ReactNode } from 'react'; -import { IconType } from 'antd/lib/notification'; - -export const openNotificationWithIcon = (message: IconType, description: ReactNode) => { - notification[message]({ message, description }); -}; diff --git a/frontend-project/src/models/tags.ts b/frontend-project/src/models/tags.ts index 0640b1a53..5708768a4 100644 --- a/frontend-project/src/models/tags.ts +++ b/frontend-project/src/models/tags.ts @@ -3,7 +3,7 @@ import { Effect } from 'dva'; import { Reducer } from 'redux'; import { router } from 'umi'; import { Tag } from '@/services/definitions'; -import { openNotificationWithIcon } from '@/models/notification'; +import { openNotificationWithIcon } from '@/models/global'; import { formatMessage } from 'umi-plugin-react/locale'; export type TagDefaultState = Tag[]; From 6f7f7feb629c41f4d531641a011d40b20212c831 Mon Sep 17 00:00:00 2001 From: Adam Dobrawy Date: Mon, 26 Oct 2020 02:53:18 +0100 Subject: [PATCH 09/13] Add POC for field validation --- frontend-project/src/pages/tags/new/index.tsx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/frontend-project/src/pages/tags/new/index.tsx b/frontend-project/src/pages/tags/new/index.tsx index 4970beedb..e3cd04fb1 100644 --- a/frontend-project/src/pages/tags/new/index.tsx +++ b/frontend-project/src/pages/tags/new/index.tsx @@ -23,13 +23,20 @@ const tailLayout = { const TagNewForm: FC = ({ dispatch }) => { const [form] = Form.useForm(); const handleSubmit = (value: Tag) => { - dispatch({ - type: 'tags/create', - payload: { ...value }, - }); + // dispatch({ + // type: 'tags/create', + // payload: { ...value }, + // }); + const response = { + name: [`To pole jest wymagane ${Math.random()}.`] + }; + form.setFields(Object + .entries(response) + .map(([name, errors]) => ({ name, errors })) + ); }; - useEffect(() => {}, []); + useEffect(() => { }, []); return ( @@ -42,7 +49,7 @@ const TagNewForm: FC = ({ dispatch }) => { name="name" rules={[ { - required: true, + // required: true, message: formatMessage({ id: 'tags-new.form.name.required-error' }), }, ]} From 93dd88d28cc431dd88484feb6e9488584a1070c8 Mon Sep 17 00:00:00 2001 From: Daxter44 Date: Mon, 26 Oct 2020 21:59:15 +0100 Subject: [PATCH 10/13] show api response in form --- frontend-project/src/models/tag.ts | 61 +++++++++++++++++++ frontend-project/src/pages/tags/new/index.tsx | 49 +++++++++------ 2 files changed, 91 insertions(+), 19 deletions(-) create mode 100644 frontend-project/src/models/tag.ts diff --git a/frontend-project/src/models/tag.ts b/frontend-project/src/models/tag.ts new file mode 100644 index 000000000..869a2955e --- /dev/null +++ b/frontend-project/src/models/tag.ts @@ -0,0 +1,61 @@ +import { create } from '@/services/tags'; +import { Effect } from 'dva'; +import { Reducer } from 'redux'; +import { router } from 'umi'; +import { openNotificationWithIcon } from '@/models/global'; +import { formatMessage } from 'umi-plugin-react/locale'; +import { Tag } from '@/services/definitions'; + +export interface TagModelState { + status?: number; + tag?: Tag; +} + +export interface TagModelType { + namespace: string; + state: TagModelState; + effects: { + create: Effect; + }; + reducers: { + changeTagStatus: Reducer; + }; +} + +const TagModel: TagModelType = { + namespace: 'tag', + state: { + status: undefined, + }, + effects: { + *create({ payload }, { call, put }) { + try { + const response = yield call(create, payload); + yield put({ + type: 'changeTagStatus', + payload: response, + }); + openNotificationWithIcon( + 'success', + formatMessage({ id: 'tags-new.page-create-notiffy-success' }) + response.data.id, + ); + router.replace(`/tags/list`); + } catch (err) { + yield put({ + type: 'changeTagStatus', + payload: err, + }); + } + }, + }, + reducers: { + changeTagStatus(state, { payload }) { + return { + ...state, + status: payload.response.status, + tag: payload.response.body, + }; + }, + }, +}; +export default TagModel; diff --git a/frontend-project/src/pages/tags/new/index.tsx b/frontend-project/src/pages/tags/new/index.tsx index e3cd04fb1..626e55888 100644 --- a/frontend-project/src/pages/tags/new/index.tsx +++ b/frontend-project/src/pages/tags/new/index.tsx @@ -1,16 +1,17 @@ import { PageHeaderWrapper } from '@ant-design/pro-layout'; -import { Button, Col, Card, Form, Input, Row } from 'antd'; +import { Button, Col, Card, Form, Input, Row, Alert } from 'antd'; import { connect } from 'dva'; import { AnyAction, Dispatch } from 'redux'; import React, { useEffect, FC } from 'react'; import { formatMessage, FormattedMessage } from 'umi-plugin-react/locale'; import { Tag } from '@/services/definitions'; +import { TagModelState } from '@/models/tag'; -interface TagNewFormProps { - name: string; +export interface TagNewFormProps { dispatch: Dispatch; + submitting: boolean; + createdTag: TagModelState; } - const layout = { labelCol: { span: 8 }, wrapperCol: { span: 16 }, @@ -20,23 +21,32 @@ const tailLayout = { wrapperCol: { offset: 8, span: 16 }, }; -const TagNewForm: FC = ({ dispatch }) => { +export interface TagMessageProps { + content: string; +} +const TagMessage = ({ content }: TagMessageProps) => ( + +); + +const TagNewForm: FC = (props: TagNewFormProps) => { const [form] = Form.useForm(); const handleSubmit = (value: Tag) => { - // dispatch({ - // type: 'tags/create', - // payload: { ...value }, - // }); - const response = { - name: [`To pole jest wymagane ${Math.random()}.`] - }; - form.setFields(Object - .entries(response) - .map(([name, errors]) => ({ name, errors })) - ); + const { dispatch } = props; + dispatch({ + type: 'tag/create', + payload: { ...value }, + }); }; - useEffect(() => { }, []); + useEffect(() => {}, []); return ( @@ -49,13 +59,14 @@ const TagNewForm: FC = ({ dispatch }) => { name="name" rules={[ { - // required: true, + required: true, message: formatMessage({ id: 'tags-new.form.name.required-error' }), }, ]} > + {props.createdTag.tag?.name && } @@ -73,4 +84,4 @@ const TagNewForm: FC = ({ dispatch }) => { ); }; -export default connect(() => ({}))(TagNewForm); +export default connect(state => ({ createdTag: (state as any).tag }))(TagNewForm); From fddfe84a9e099114575af0a6e250d3d3537cc4e8 Mon Sep 17 00:00:00 2001 From: Daxter44 Date: Tue, 27 Oct 2020 07:16:22 +0100 Subject: [PATCH 11/13] fix errors displaying --- frontend-project/src/pages/tags/new/index.tsx | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/frontend-project/src/pages/tags/new/index.tsx b/frontend-project/src/pages/tags/new/index.tsx index 626e55888..1cc95a792 100644 --- a/frontend-project/src/pages/tags/new/index.tsx +++ b/frontend-project/src/pages/tags/new/index.tsx @@ -1,5 +1,5 @@ import { PageHeaderWrapper } from '@ant-design/pro-layout'; -import { Button, Col, Card, Form, Input, Row, Alert } from 'antd'; +import { Button, Col, Card, Form, Input, Row } from 'antd'; import { connect } from 'dva'; import { AnyAction, Dispatch } from 'redux'; import React, { useEffect, FC } from 'react'; @@ -10,7 +10,7 @@ import { TagModelState } from '@/models/tag'; export interface TagNewFormProps { dispatch: Dispatch; submitting: boolean; - createdTag: TagModelState; + TagState: TagModelState; } const layout = { labelCol: { span: 8 }, @@ -20,22 +20,6 @@ const layout = { const tailLayout = { wrapperCol: { offset: 8, span: 16 }, }; - -export interface TagMessageProps { - content: string; -} -const TagMessage = ({ content }: TagMessageProps) => ( - -); - const TagNewForm: FC = (props: TagNewFormProps) => { const [form] = Form.useForm(); const handleSubmit = (value: Tag) => { @@ -44,6 +28,7 @@ const TagNewForm: FC = (props: TagNewFormProps) => { type: 'tag/create', payload: { ...value }, }); + form.setFields(Object.entries(props.TagState.tag).map(([name, errors]) => ({ name, errors }))); }; useEffect(() => {}, []); @@ -66,7 +51,6 @@ const TagNewForm: FC = (props: TagNewFormProps) => { > - {props.createdTag.tag?.name && } @@ -84,4 +68,4 @@ const TagNewForm: FC = (props: TagNewFormProps) => { ); }; -export default connect(state => ({ createdTag: (state as any).tag }))(TagNewForm); +export default connect(state => ({ TagState: (state as any).tag }))(TagNewForm); From 4a527dc3625c7ca771211990b399fb47f84bdfab Mon Sep 17 00:00:00 2001 From: Daxter44 Date: Tue, 27 Oct 2020 07:22:29 +0100 Subject: [PATCH 12/13] change createTag property name to tagState --- frontend-project/src/pages/tags/new/index.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend-project/src/pages/tags/new/index.tsx b/frontend-project/src/pages/tags/new/index.tsx index 1cc95a792..625380fd4 100644 --- a/frontend-project/src/pages/tags/new/index.tsx +++ b/frontend-project/src/pages/tags/new/index.tsx @@ -10,7 +10,7 @@ import { TagModelState } from '@/models/tag'; export interface TagNewFormProps { dispatch: Dispatch; submitting: boolean; - TagState: TagModelState; + tagState: TagModelState; } const layout = { labelCol: { span: 8 }, @@ -28,7 +28,7 @@ const TagNewForm: FC = (props: TagNewFormProps) => { type: 'tag/create', payload: { ...value }, }); - form.setFields(Object.entries(props.TagState.tag).map(([name, errors]) => ({ name, errors }))); + form.setFields(Object.entries(props.tagState.tag).map(([name, errors]) => ({ name, errors }))); }; useEffect(() => {}, []); @@ -68,4 +68,4 @@ const TagNewForm: FC = (props: TagNewFormProps) => { ); }; -export default connect(state => ({ TagState: (state as any).tag }))(TagNewForm); +export default connect(state => ({ tagState: (state as any).tag }))(TagNewForm); From ecc6a695283d11eb070b3dd569540fd0da0c416b Mon Sep 17 00:00:00 2001 From: Daxter44 Date: Tue, 27 Oct 2020 22:49:10 +0100 Subject: [PATCH 13/13] fix error map on submit --- frontend-project/src/models/tag.ts | 6 ++---- frontend-project/src/pages/tags/new/index.tsx | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/frontend-project/src/models/tag.ts b/frontend-project/src/models/tag.ts index 869a2955e..792fff859 100644 --- a/frontend-project/src/models/tag.ts +++ b/frontend-project/src/models/tag.ts @@ -21,12 +21,10 @@ export interface TagModelType { changeTagStatus: Reducer; }; } - +const TagState: TagModelState = { status: 1, tag: { name: '', id: 0 } }; const TagModel: TagModelType = { namespace: 'tag', - state: { - status: undefined, - }, + state: TagState, effects: { *create({ payload }, { call, put }) { try { diff --git a/frontend-project/src/pages/tags/new/index.tsx b/frontend-project/src/pages/tags/new/index.tsx index 625380fd4..eaabe2381 100644 --- a/frontend-project/src/pages/tags/new/index.tsx +++ b/frontend-project/src/pages/tags/new/index.tsx @@ -22,15 +22,16 @@ const tailLayout = { }; const TagNewForm: FC = (props: TagNewFormProps) => { const [form] = Form.useForm(); + const handleSubmit = (value: Tag) => { const { dispatch } = props; dispatch({ type: 'tag/create', payload: { ...value }, }); - form.setFields(Object.entries(props.tagState.tag).map(([name, errors]) => ({ name, errors }))); }; + form.setFields(Object.entries(props?.tagState.tag).map(([name, errors]) => ({ name, errors }))); useEffect(() => {}, []); return (