tycho-components 0.0.7 → 0.0.9-SNAPSHOT

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,7 +19,8 @@
19
19
  color: var(--text-secondary);
20
20
  }
21
21
  }
22
- i .ds-icon {
22
+
23
+ > .ds-icon {
23
24
  margin-left: auto;
24
25
  margin-bottom: auto;
25
26
  }
@@ -45,6 +45,7 @@ export default function AppToast() {
45
45
  }
46
46
  }, [state.toastLoading]);
47
47
  useEffect(() => {
48
+ console.log(state.message);
48
49
  if (state.message && state.message.value !== '') {
49
50
  switch (state.message.type) {
50
51
  case 'error':
@@ -3,13 +3,13 @@ import { yupResolver } from '@hookform/resolvers/yup';
3
3
  import { useContext } from 'react';
4
4
  import { useForm } from 'react-hook-form';
5
5
  import { useTranslation } from 'react-i18next';
6
+ import { TextField } from 'tycho-storybook';
6
7
  import * as yup from 'yup';
7
8
  import AppModal from '../../AppModal';
8
9
  import CommonContext from '../../configs/CommonContext';
9
- import { toastLoading } from '../../configs/store/actions';
10
+ import { dispatchError, dispatchLoading } from '../../configs/MessageUtils';
10
11
  import ParticipantService from '../types/ParticipantService';
11
12
  import './style.scss';
12
- import { TextField } from 'tycho-storybook';
13
13
  export default function ParticipantCreate({ document, onClose, onCreate, }) {
14
14
  const { t } = useTranslation('participants');
15
15
  const { dispatch, state } = useContext(CommonContext);
@@ -20,13 +20,16 @@ export default function ParticipantCreate({ document, onClose, onCreate, }) {
20
20
  const handleAdd = () => {
21
21
  if (state.toastLoading)
22
22
  return;
23
- dispatch(toastLoading(true));
23
+ dispatchLoading(true, dispatch);
24
24
  ParticipantService.add(document, createdForm.getValues())
25
25
  .then((r) => {
26
26
  onCreate(r.data);
27
+ })
28
+ .catch((err) => {
29
+ dispatchError({ err, dispatch, t, key: 'participants' });
27
30
  })
28
31
  .finally(() => {
29
- dispatch(toastLoading(false));
32
+ dispatchLoading(false, dispatch);
30
33
  });
31
34
  };
32
35
  return (_jsx(AppModal, { title: t('modal.add.title'), className: "modal-participant", close: onClose, confirm: handleAdd, disableConfirm: !createdForm.formState.isValid, children: _jsxs("div", { className: "participant-container", children: [_jsx(TextField, { label: t('modal.input.code'), attr: "code",
@@ -3,6 +3,7 @@ import { useContext } from 'react';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import AppModalRemove from '../../AppModal/AppModalRemove';
5
5
  import CommonContext from '../../configs/CommonContext';
6
+ import { dispatchLoading } from '../../configs/MessageUtils';
6
7
  import { toastLoading } from '../../configs/store/actions';
7
8
  import ParticipantService from '../types/ParticipantService';
8
9
  import './style.scss';
@@ -12,7 +13,7 @@ export default function ParticipantRemove({ participant, participants, document,
12
13
  const handleRemove = () => {
13
14
  if (state.toastLoading || !participant)
14
15
  return;
15
- dispatch(toastLoading(true));
16
+ dispatchLoading(true, dispatch);
16
17
  ParticipantService.remove(document, participant.code)
17
18
  .then(() => {
18
19
  const list = participants?.filter((p) => p.code !== participant.code) || [];
@@ -41,7 +41,9 @@ export default function Participants({ document, participants, onChange, }) {
41
41
  if (participants.length > 0)
42
42
  setParticipant(participants[0]);
43
43
  }, []);
44
- return (_jsxs("div", { className: "participants-container", children: [_jsxs("div", { className: "header", children: [_jsx("h3", { children: t('label.title') }), _jsx("div", { className: "actions", children: _jsxs("button", { type: "button", className: "action", onClick: () => setOpenCreate(true), children: [_jsx(FontAwesomeIcon, { icon: faPlus, title: t('button.label.add') }), _jsx("span", { className: "ms-2", children: t('button.label.add') })] }) })] }), _jsx("div", { className: "body", children: participant && (_jsxs(_Fragment, { children: [_jsx(Form.Select, { onChange: (e) => setParticipant(participants[Number(e.target.value)]), children: participants.map((el, idx) => (_jsx("option", { value: idx, selected: el.code === participant.code, children: `${el.code} - ${el.name}` }, idx))) }), _jsx(AppEditable, { translation: "participants", group: "participant", save: handleSave, item: { ...participant, uid: document }, fields: PARTICIPANT_FIELDS, className: "fields", reference: "code" }), _jsx("div", { className: "footer", children: _jsxs(Button, { variant: "danger", onClick: () => {
44
+ return (_jsxs("div", { className: "participants-container", children: [_jsxs("div", { className: "header", children: [_jsx("h3", { children: t('label.title') }), _jsx("div", { className: "actions", children: _jsxs("button", { type: "button", className: "action", onClick: () => setOpenCreate(true), children: [_jsx(FontAwesomeIcon, { icon: faPlus, title: t('button.label.add') }), _jsx("span", { className: "ms-2", children: t('button.label.add') })] }) })] }), _jsx("div", { className: "body", children: participant && (_jsxs(_Fragment, { children: [_jsx(Form.Select, { onChange: (e) => setParticipant(participants[Number(e.target.value)]), value: participant
45
+ ? participants.findIndex((p) => p.code === participant.code)
46
+ : 0, children: participants.map((el, idx) => (_jsx("option", { value: idx, children: `${el.code} - ${el.name}` }, idx))) }), _jsx(AppEditable, { translation: "participants", group: "participant", save: handleSave, item: { ...participant, uid: document }, fields: PARTICIPANT_FIELDS, className: "fields", reference: "code" }), _jsx("div", { className: "footer", children: _jsxs(Button, { variant: "danger", onClick: () => {
45
47
  setParticipant(participant);
46
48
  setOpenRemove(true);
47
49
  }, children: [_jsx(FontAwesomeIcon, { icon: faTrash }), _jsx("span", { className: "ms-1", children: t('common:button.remove') })] }) })] })) }), participant && openRemove && (_jsx(ParticipantRemove, { document: document, onChange: (list) => {
@@ -28,6 +28,7 @@ export declare const commonResources: {
28
28
  'modal.add.title': string;
29
29
  'modal.input.code': string;
30
30
  'modal.input.name': string;
31
+ 'participant.code.exists': string;
31
32
  };
32
33
  };
33
34
  'pt-BR': {
@@ -58,6 +59,7 @@ export declare const commonResources: {
58
59
  'modal.add.title': string;
59
60
  'modal.input.code': string;
60
61
  'modal.input.name': string;
62
+ 'participant.code.exists': string;
61
63
  };
62
64
  };
63
65
  };
@@ -10,11 +10,13 @@ type ErrorDispatcher = {
10
10
  err: any;
11
11
  dispatch: React.Dispatch<StoreAction>;
12
12
  t: TFunction;
13
+ key?: string;
13
14
  };
14
- export declare const dispatchError: ({ err, dispatch, t }: ErrorDispatcher) => void;
15
+ export declare const dispatchLoading: (val: boolean, dispatch: React.Dispatch<StoreAction>) => void;
16
+ export declare const dispatchError: ({ err, dispatch, t, key }: ErrorDispatcher) => void;
15
17
  export declare const dispatchMessage: ({ key, ns, dispatch, t, }: MessageDispatcher) => void;
16
18
  declare const MessageUtils: {
17
- dispatchError: ({ err, dispatch, t }: ErrorDispatcher) => void;
19
+ dispatchError: ({ err, dispatch, t, key }: ErrorDispatcher) => void;
18
20
  dispatchMessage: ({ key, ns, dispatch, t, }: MessageDispatcher) => void;
19
21
  };
20
22
  export default MessageUtils;
@@ -1,6 +1,9 @@
1
- import { message } from '../configs/store/actions';
1
+ import { message, toastLoading } from '../configs/store/actions';
2
+ export const dispatchLoading = (val, dispatch) => {
3
+ dispatch(toastLoading(val));
4
+ };
2
5
  // TODO: improve
3
- export const dispatchError = ({ err, dispatch, t }) => {
6
+ export const dispatchError = ({ err, dispatch, t, key }) => {
4
7
  if (!err.response) {
5
8
  dispatch(message({ value: t(err), type: 'error' }));
6
9
  return;
@@ -17,7 +20,8 @@ export const dispatchError = ({ err, dispatch, t }) => {
17
20
  errorKey = err.response.data.description;
18
21
  if (err.response.data.errors && err.response.data.errors.length > 0)
19
22
  errorKey = err.response.data.errors[0].description;
20
- dispatch(message({ value: t(`message:${errorKey}`), type: 'error' }));
23
+ const value = t(`${key ? key : 'message'}:${errorKey}`);
24
+ dispatch(message({ value: value, type: 'error' }));
21
25
  };
22
26
  export const dispatchMessage = ({ key, ns, dispatch, t, }) => {
23
27
  const entry = ns ? `${ns}:${key}` : `message:${key}`;
@@ -14,6 +14,7 @@ export declare const ParticipantsTexts: {
14
14
  'modal.add.title': string;
15
15
  'modal.input.code': string;
16
16
  'modal.input.name': string;
17
+ 'participant.code.exists': string;
17
18
  };
18
19
  'pt-BR': {
19
20
  'label.title': string;
@@ -30,5 +31,6 @@ export declare const ParticipantsTexts: {
30
31
  'modal.add.title': string;
31
32
  'modal.input.code': string;
32
33
  'modal.input.name': string;
34
+ 'participant.code.exists': string;
33
35
  };
34
36
  };
@@ -14,6 +14,7 @@ export const ParticipantsTexts = {
14
14
  'modal.add.title': 'Add new participant',
15
15
  'modal.input.code': 'ID',
16
16
  'modal.input.name': 'Name',
17
+ 'participant.code.exists': 'The participant code provided is already in use.',
17
18
  },
18
19
  'pt-BR': {
19
20
  'label.title': 'Participantes',
@@ -30,5 +31,6 @@ export const ParticipantsTexts = {
30
31
  'modal.add.title': 'Adicionar novo participante',
31
32
  'modal.input.code': 'ID',
32
33
  'modal.input.name': 'Nome',
34
+ 'participant.code.exists': 'O código de participante fornecido já está em uso.',
33
35
  },
34
36
  };
package/dist/index.d.ts CHANGED
@@ -7,3 +7,4 @@ export { default as AppModalConfirm } from './AppModal/AppModalConfirm';
7
7
  export { default as AppModalRemove } from './AppModal/AppModalRemove';
8
8
  export { commonResources } from './configs/Localization';
9
9
  export { CommonProvider } from './configs/CommonContext';
10
+ export { default as MessageUtils } from './configs/MessageUtils';
package/dist/index.js CHANGED
@@ -7,3 +7,4 @@ export { default as AppModalConfirm } from './AppModal/AppModalConfirm';
7
7
  export { default as AppModalRemove } from './AppModal/AppModalRemove';
8
8
  export { commonResources } from './configs/Localization';
9
9
  export { CommonProvider } from './configs/CommonContext';
10
+ export { default as MessageUtils } from './configs/MessageUtils';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-components",
3
3
  "private": false,
4
- "version": "0.0.7",
4
+ "version": "0.0.9-SNAPSHOT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {