forstok-ui-lib 6.20.2 → 6.21.2

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.
Files changed (29) hide show
  1. package/dist/index.d.ts +10 -49
  2. package/dist/index.js +571 -1167
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +569 -1165
  5. package/dist/index.mjs.map +1 -1
  6. package/package.json +1 -1
  7. package/src/assets/javascripts/function.ts +21 -0
  8. package/src/assets/javascripts/helper.ts +11 -2
  9. package/src/components/index.ts +0 -1
  10. package/src/components/link/index.tsx +4 -1
  11. package/src/components/link/styles.ts +152 -144
  12. package/src/components/link/typed.ts +10 -0
  13. package/src/typeds/shares.typed.ts +26 -26
  14. package/src/components/masterTable/index.tsx +0 -649
  15. package/src/components/masterTable/partials/datas/confirm.tsx +0 -92
  16. package/src/components/masterTable/partials/datas/index.tsx +0 -81
  17. package/src/components/masterTable/partials/editors/date.bare.tsx +0 -39
  18. package/src/components/masterTable/partials/editors/date.tsx +0 -123
  19. package/src/components/masterTable/partials/editors/image.tsx +0 -61
  20. package/src/components/masterTable/partials/editors/input.bare.tsx +0 -127
  21. package/src/components/masterTable/partials/editors/input.tsx +0 -140
  22. package/src/components/masterTable/partials/editors/label.tsx +0 -128
  23. package/src/components/masterTable/partials/editors/select.bare.tsx +0 -104
  24. package/src/components/masterTable/partials/editors/select.tsx +0 -142
  25. package/src/components/masterTable/partials/editors/switch.tsx +0 -56
  26. package/src/components/masterTable/partials/editors/tag.tsx +0 -49
  27. package/src/components/masterTable/partials/editors/textarea.tsx +0 -7
  28. package/src/components/masterTable/styles.tsx +0 -1011
  29. package/src/components/masterTable/typed.ts +0 -87
@@ -1,92 +0,0 @@
1
- import CheckboxComponent from '../../../../components/checkbox';
2
- import IconComponent from '../../../../components/icon';
3
- import { MasterTableBodyContent } from '../../../../components/masterTable/styles';
4
- import type { TDataPartial } from '../../../../components/masterTable/typed';
5
-
6
- const ConfirmDataPartial = ({ data, heightContent, firstHeaderColumnsWidth, evCheckbox, headerColumns, switchEditor, totalColGroupWidth, lastHeaderColumnsWidth, evRemove, type, isRemovable }: TDataPartial) => {
7
- return (
8
- data.map((content: any, idx: number) => {
9
- const heightAll = heightContent ? (content.variants.length * heightContent) : content.variants.length;
10
- let keyIdx = idx;
11
- switch(type) {
12
- case 'putaway-inbound':
13
- keyIdx = content.id;
14
- break;
15
- default:
16
- keyIdx = idx ;
17
- break;
18
- }
19
- return (
20
- <MasterTableBodyContent key={keyIdx} className='_refMasterTableBodyContent' style={{ height: heightAll }}>
21
- <div className='cell-colGroup' style={{ height: heightAll }} key={0}>
22
- <div key={0} className='cell cell-checkbox' style={{ width: firstHeaderColumnsWidth, height: heightAll }}>
23
- <article>
24
- <div>{idx + 1}</div>
25
- <CheckboxComponent id={`checkbox-list-${idx}`} name='checkbox-list' extendKey={idx.toString()} onClick={evCheckbox} />
26
- </article>
27
- </div>
28
- {
29
- headerColumns.filter(header => !header?.isHidden).filter(head => head.type === 'colGroup').map((head, headIdx)=> {
30
- const valueKey = content[head.key]
31
- const idxKey = headIdx+1
32
- const error = content?.[head.key+'_error'] || ''
33
- const editorEl = switchEditor(idx, head, valueKey, error, undefined, heightAll, content)
34
- return <div key={idxKey} data-idx={idx} data-key={head.key} className={`cell cell-${head.fieldType} ${error ? 'cell-error' : ''}`} style={{ width: head.width, height: heightAll }}>{editorEl}</div>
35
- })
36
- }
37
- </div>
38
- <div className='cell-rowGroup' style={{ left: totalColGroupWidth, overflow: 'hidden' }} key={1}>
39
- {
40
- content.locations.map((locations: any, locationIdx: number) => {
41
- const reKey = type === 'create-adjustment' ? locationIdx+'-'+(locations.batchId?.value||'0')+'-'+(locations.location||'0') : locationIdx
42
- let hasSaveKey: string[] = []
43
- return (
44
- <div className='cell-row' key={reKey} data-row={locationIdx} style={{ height: heightContent }} >
45
- {
46
- headerColumns.filter(header => !header?.isHidden).filter(head => head.type !== 'colGroup').map((head, headIdx)=> {
47
- const idxKey= headIdx+1;
48
- let valueKey = null;
49
- let error = '';
50
- let uneditable = false;
51
- let mainKey = head.key.replace('locations-', '');
52
- if(mainKey.indexOf('-') === -1) {
53
- valueKey = locations[mainKey];
54
- error = content?.locations?.[locationIdx]?.[mainKey+'_error'] || '';
55
- }else {
56
- const modifiedMainKey = mainKey.split('-');
57
- const firstKey = modifiedMainKey[0];
58
- const secondKey = modifiedMainKey[1];
59
- const keyLength = locations[firstKey] ? locations[firstKey].length : 0;
60
- if(keyLength) {
61
- let index = 0;
62
- if(hasSaveKey.filter(key => key === mainKey).length) index = hasSaveKey.filter(key => key === mainKey).length;
63
- valueKey = (keyLength > index) ? locations[firstKey][index][secondKey] : null;
64
- error = (keyLength > index) ? content?.locations?.[locationIdx]?.[firstKey][index][secondKey+'_error'] : null;
65
- hasSaveKey.push(mainKey);
66
- }
67
- }
68
- if ((head?.condition === 'adjustLocation' || head?.condition === 'countAdjustment') && !content.locations[locationIdx]?.location) {
69
- uneditable = true;
70
- }
71
- const editorEl = switchEditor(idx, head, valueKey, error, locationIdx);
72
- return <div key={idxKey} data-idx={idx} data-key={head.key} data-row={locationIdx} className={`cell cell-${head.fieldType} ${error ? 'cell-error' : ''} ${uneditable ? 'cell-disabled': ''}`} style={{ width: head.width }}>{editorEl}</div>;
73
- })
74
- }
75
- {isRemovable ? (
76
- <div key={headerColumns.length+1} data-idx={idx} data-key='trash' data-row={locationIdx} className='cell cell-trash' onClick={evRemove} style={{ width: lastHeaderColumnsWidth }}>
77
- <div>
78
- <IconComponent $name='trash' $width='18px' data-qa-id={`mt-icon-trash-${idx}${(locationIdx !== null ? '-' + locationIdx : '')}`} />
79
- </div>
80
- </div> ) : null}
81
- </div>
82
- )
83
- })
84
- }
85
- </div>
86
- </MasterTableBodyContent>
87
- );
88
- })
89
- )
90
- }
91
-
92
- export default ConfirmDataPartial
@@ -1,81 +0,0 @@
1
- import ButtonComponent from '../../../button';
2
- import CheckboxComponent from '../../../checkbox';
3
- import IconComponent from '../../../icon';
4
- import { MasterTableBodyContent } from '../../styles';
5
- import type { TDataPartial } from '../../typed';
6
-
7
- const DataPartial = ({data, firstHeaderColumnsWidth, evCheckbox, headerColumns, switchEditor, lastHeaderColumnsWidth, evRemove, type, isRemovable}: TDataPartial) => {
8
- return (
9
- data.map((content: any, idx: number) => {
10
- let keyIdx = idx;
11
- switch(type) {
12
- case 'create-promotion':
13
- keyIdx = content.id;
14
- break;
15
- case 'create-adjustment': case 'create-price': case 'create-inbound': case 'create-outbound': case 'create-transfer': case 'confirm-adjustment': case 'confirm-inbound': case 'confirm-outbound':
16
- keyIdx = content.id;
17
- break;
18
- case 'create-return':
19
- keyIdx = content?.product?.id || idx;
20
- break;
21
- // case 'create-paymentreceive':
22
- // keyIdx = content.invoiceID
23
- // break
24
- default:
25
- keyIdx = idx;
26
- break;
27
- }
28
- let extraClass = '';
29
- if (type === 'edit-picklist') {
30
- extraClass = content.qtyOrdered === content.qtyPicked ? 'is-fullfilled' : '';
31
- } else if(type === 'create-package') {
32
- extraClass = content.qtyOrdered === content.qtyPack ? 'is-fullfilled' : '';
33
- } else if(type === 'create-return') {
34
- extraClass = (content.qtyOrdered - content.qtyReturned) === content.qtyToReturn ? 'is-fullfilled' : '';
35
- }
36
-
37
- return (
38
- <MasterTableBodyContent key={keyIdx} $mode={type} id={`row-${keyIdx}`} className={`_refMasterTableBodyContent ${extraClass}`}>
39
- <div className='cell-colGroup' key={0}>
40
- <div key={0} className='cell cell-checkbox' style={{ width: firstHeaderColumnsWidth }}>
41
- {isRemovable ? (
42
- <article>
43
- <div>{idx + 1}</div>
44
- <div><CheckboxComponent id={`checkbox-list-${idx}`} name='checkbox-list' extendKey={idx.toString()} onClick={evCheckbox} ></CheckboxComponent></div>
45
- </article>
46
- ) : <div>{idx + 1}</div>}
47
- </div>
48
- {
49
- headerColumns.filter(header => !header?.isHidden).filter(head => head.type === 'colGroup').map((head, headIdx)=> {
50
- const valueKey = content[head.key];
51
- const idxKey = headIdx+1;
52
- const error = content?.[head.key+'_error'] || '';
53
- const editorEl = switchEditor(idx, head, valueKey, error, undefined, 'auto', content);
54
- let isDisabledCell = false;
55
- if (type === 'create-price' && (head.key !== 'price' && head.key !== 'salePrice' && head.key !== 'item')) {
56
- const aliasKey = head.key.split('_');
57
- if(aliasKey[1] === 'salePrice' || aliasKey[1] === 'saleStartAt' || aliasKey[1] === 'saleEndAt') {
58
- if (content[`${aliasKey[0]}_salePrice`] === undefined && content[`${aliasKey[0]}_saleStartAt`] === undefined && content[`${aliasKey[0]}_saleEndAt`] === undefined) {
59
- isDisabledCell = true;
60
- }
61
- } else if(valueKey === undefined) {
62
- isDisabledCell = true;
63
- }
64
- }
65
- return <div key={idxKey} data-idx={idx} data-key={head.key} className={`cell cell-${head.fieldType} ${isDisabledCell ? 'cell-disabled' : '' } ${error ? 'cell-error' : ''}`} style={{ width: head.width }}>{editorEl}</div>;
66
- })
67
- }
68
- {isRemovable ? (
69
- <div key={headerColumns.length+1} data-idx={idx} data-key='trash' className='cell cell-trash' style={{ width: lastHeaderColumnsWidth }} onClick={evRemove}>
70
- <div>
71
- <IconComponent $name='trash' $width='18px' data-qa-id={`mt-icon-trash-${idx}`} />
72
- </div>
73
- </div> ) : null}
74
- </div>
75
- </MasterTableBodyContent>
76
- )
77
- })
78
- );
79
- }
80
-
81
- export default DataPartial;
@@ -1,39 +0,0 @@
1
- import { useCallback } from 'react';
2
- import moment from 'moment';
3
- import TextComponent from '../../../text';
4
- import DateComponent from '../../../date';
5
- import type { TEditorProps } from '../../typed';
6
-
7
- const DateBareEditors = ({ head, value, evChange, idx, variantIdx, error, isForceUpdate, setForceUpdate }:Omit<TEditorProps, 'evCloseEditor'>) => {
8
- const eckey = `${head.key}-${idx}${(variantIdx !== undefined ? '-'+variantIdx : '')}`;
9
-
10
- const evCustom = useCallback((valueCustom: any) => {
11
- const keyEl = document.getElementById('cur-key');
12
- const currentKey = keyEl ? keyEl.innerHTML : '';
13
- if(currentKey && (currentKey === eckey)) {
14
- evChange(head, valueCustom, idx, variantIdx);
15
- }
16
- }, [eckey, head, idx, variantIdx, evChange])
17
-
18
- const saveFormat = head.format || 'DD/MM/YYYY';
19
-
20
- const evChangeDate = (name: string, value: Date | null) => {
21
- const keyEl = document.getElementById('cur-key');
22
- keyEl && (keyEl.innerHTML = eckey);
23
- const _value = value ? moment(value).format(saveFormat) : value;
24
- evCustom(_value);
25
- }
26
-
27
- const qaId = `${(head.name).toLowerCase().replaceAll(' ','-')}-${idx}${(variantIdx !== undefined ? '-'+variantIdx : '')}`;
28
- const _value = value ? moment(value, saveFormat).toDate() : value;
29
-
30
- return (
31
- <div className='master-editor'>
32
- {
33
- (value === undefined && head?.condition === 'sale') ? <TextComponent $color='grey'>No Listing yet!</TextComponent> : <DateComponent saveFormat={saveFormat} evChange={evChangeDate} name={head.fieldType+'_'+head.key} value={_value} {...head?.allowEmpty && { allowEmpty: true }} {...error && { isError: true, 'data-tip':error, 'data-place': 'top', 'data-type': 'error' }} isForceUpdate={isForceUpdate} setForceUpdate={setForceUpdate} data-qa-id={`mt-field-date-${qaId}`} {...head?.showFormat && { showFormat: head.showFormat }} />
34
- }
35
- </div>
36
- );
37
- }
38
-
39
- export default DateBareEditors;
@@ -1,123 +0,0 @@
1
- import { useState, useEffect, useCallback, useRef } from 'react';
2
- import type { ReactNode } from 'react';
3
- import moment from 'moment';
4
- import DateComponent from '../../../date';
5
- import ErrorComponent from '../../../error';
6
- import TextComponent from '../../../text';
7
- import type { TMouseEvent } from '../../../../typeds/base.typed';
8
- import type { TEditorProps } from '../../typed';
9
-
10
- const DateEditors = ({ head, value, height, evChange, idx, variantIdx, error, evCloseEditor }: TEditorProps) => {
11
- const [isEditing, setEdit] = useState<boolean>(false);
12
- const [valueFormState, setValueFormState] = useState<Date | null>(value || null);
13
- const [isFirstLoadEditor, setFirstLoad] = useState<boolean>(true);
14
- const [ isForceUpdate, setForceUpdate ] = useState(false);
15
-
16
- const datepickerRef = useRef(null);
17
- const saveFormat = head.format || 'DD/MM/YYYY';
18
- const eckey = `${head.key}-${idx}${(variantIdx !== undefined ? '-'+variantIdx : '')}`;
19
-
20
- useEffect(() => {
21
- const _value = value ? moment(value, saveFormat).toDate() : value;
22
- setValueFormState(_value);
23
- }, [saveFormat, value])
24
-
25
- const evCustom = useCallback((valueCustom: any) => {
26
- const keyEl = document.getElementById('cur-key');
27
- const currentKey = keyEl ? keyEl.innerHTML : '';
28
- if(currentKey && (currentKey === eckey)) {
29
- evChange(head, valueCustom, idx, variantIdx);
30
- evCloseEditor(() => { setEdit(false) });
31
- }
32
- }, [eckey, head, idx, variantIdx, evChange, evCloseEditor])
33
-
34
- useEffect(() => {
35
- if (!isFirstLoadEditor) {
36
- const _value = valueFormState ? moment(valueFormState).format(saveFormat) : valueFormState;
37
- evCustom(_value);
38
- }
39
- else {
40
- setFirstLoad(false);
41
- }
42
- }, [valueFormState, evCustom, isFirstLoadEditor, saveFormat])
43
-
44
- useEffect(() => {
45
- const docBody = document.body;
46
- const evClick = (e: Event) => {
47
- if(!isEditing) {
48
- return false;
49
- }
50
- const target = e.target as HTMLBodyElement;
51
- if (target.closest('.react-datepicker') || target.closest('.cell-wrapper')) {
52
- return false;
53
- } else if(!target.closest('.master-editor')) {
54
- setValueFormState(valueFormState);
55
- evCloseEditor(() => { setEdit(false) });
56
- return;
57
- }
58
- };
59
- docBody.addEventListener('click', evClick);
60
- return () => docBody.removeEventListener('click', evClick);
61
- }, [valueFormState, isEditing, evCloseEditor])
62
-
63
- const evClick: TMouseEvent = e => {
64
- e.preventDefault();
65
- const target = e.target as HTMLInputElement;
66
- if (target.closest('.cell-disabled')) {
67
- return false;
68
- }
69
- const keyEl = document.getElementById('cur-key') as HTMLDivElement;
70
- keyEl && (keyEl.innerHTML = eckey);
71
- setEdit(!isEditing);
72
- const cellEl = target.closest('.cell') as HTMLDivElement;
73
- if (!isEditing) {
74
- cellEl && (cellEl.classList.add('cell-editing'));
75
- }
76
- else {
77
- cellEl && (cellEl.classList.remove('cell-editing'));
78
- }
79
- }
80
-
81
- const evChangeDate = (name: string, value: Date | null) => {
82
- setValueFormState(value);
83
- setForceUpdate(true);
84
- }
85
-
86
- const qaId = `${(head.name).toLowerCase().replaceAll(' ','-')}-${idx}${(variantIdx !== undefined ? '-'+variantIdx : '')}`;
87
-
88
- return (
89
- !isEditing ? (
90
- <section onClick={evClick} className="cell-wrapper">
91
- {
92
- head.multiline ? (
93
- <>
94
- {
95
- (!valueFormState && error) ? <TextComponent $color='blue' style={{ fontWeight: 500 }}>+ Add</TextComponent> : <div className='truncate-overflow' style={{ maxHeight: height ? (parseInt(height as string) - 34) : 'auto' }} data-qa-id={`mt-input-label-${qaId}`}>
96
- {
97
- ((head?.showFormat && valueFormState) ? moment(valueFormState, saveFormat).format(head.showFormat) : valueFormState as ReactNode)
98
- }
99
- </div>
100
- }
101
- {error && <ErrorComponent $mode='table'>{error}</ErrorComponent> }
102
- </>
103
- ) : (
104
- <>
105
- {
106
- (!valueFormState && error) ? <TextComponent $color='blue' style={{ fontWeight: 500 }}>+ Add</TextComponent> : <div data-qa-id={`mt-input-label-${qaId}`}>
107
- {
108
- ((head?.showFormat && valueFormState) ? moment(valueFormState, saveFormat).format(head.showFormat) : valueFormState as ReactNode)
109
- }
110
- </div>
111
- }
112
- {error && <ErrorComponent $mode='table'>{error}</ErrorComponent> }
113
- </>
114
- )
115
- }
116
- </section>
117
- ) : (
118
- <div className='master-editor'><DateComponent ref={datepickerRef} saveFormat={saveFormat} evChange={evChangeDate} name={head.fieldType+'_'+head.key} {...valueFormState && { value: valueFormState }} isError={error ? true : false} isForceUpdate={isForceUpdate} setForceUpdate={setForceUpdate} data-qa-id={`mt-field-date-${qaId}`} {...head?.allowEmpty && { allowEmpty: head.allowEmpty }} {...head?.showFormat && { showFormat: head.showFormat }} /></div>
119
- )
120
- );
121
- }
122
-
123
- export default DateEditors;
@@ -1,61 +0,0 @@
1
- import { useEffect, useCallback } from 'react';
2
- import ErrorComponent from '../../../error';
3
- import ImageComponent from '../../../image';
4
- import TextComponent from '../../../text';
5
- import type { TMouseEvent } from '../../../../typeds/base.typed';
6
- import type { TEditorProps } from '../../typed';
7
-
8
- const ImageEditors = ({ head, value, evChange, evOpenPopup, idx, variantIdx, resultPopup, setResultPopup, error, evCloseEditor }: TEditorProps) => {
9
- const eckey = `${head.key}-${idx}${(variantIdx !== undefined ? '-'+variantIdx : '')}`;
10
-
11
- const evCustom = useCallback((valueFormState: any) => {
12
- const keyEl = document.getElementById('cur-key') as HTMLDivElement;
13
- const currentKey = keyEl ? keyEl.innerHTML : '';
14
- if (currentKey && (currentKey === eckey)) {
15
- evChange(head, valueFormState, idx, variantIdx);
16
- evCloseEditor();
17
- }
18
- }, [eckey, head, idx, variantIdx, evChange, evCloseEditor])
19
-
20
- useEffect(()=> {
21
- if (resultPopup && ('image' in resultPopup)) {
22
- setResultPopup && setResultPopup(null);
23
- evCustom(resultPopup.image);
24
- }
25
- return () => {
26
- setResultPopup && setResultPopup(null);
27
- }
28
- }, [resultPopup, setResultPopup, evCustom])
29
-
30
- const evClick: TMouseEvent = e => {
31
- e.preventDefault();
32
- const target = e.target as HTMLElement;
33
- if (target.closest('.cell-disabled')) {
34
- return false;
35
- }
36
- const keyEl = document.getElementById('cur-key') as HTMLDivElement;
37
- keyEl && (keyEl.innerHTML = eckey);
38
- const cellEl = target.closest('.cell') as HTMLDivElement;
39
- cellEl && (cellEl.classList.add('cell-editing'));
40
- evOpenPopup && evOpenPopup(e, 'cell-wrapper');
41
- }
42
-
43
- return (
44
- <section className="cell-wrapper" onClick={evClick} data-popup='table-image' data-detail={JSON.stringify({ title: head.name, value: value, head: head })}>
45
- {
46
- (error && !(error.indexOf('minimum') !== -1 || error.indexOf('maximum') !== -1)) ?
47
- <TextComponent $color='blue' style={{ fontWeight: 500 }}>+ Add</TextComponent> :
48
- <div>
49
- {
50
- value && <figure className="table-image-figure" data-qa-id={`mt-image-${(head.name).toLowerCase().replaceAll(' ','-')}-${idx}${(variantIdx !== undefined ? '-'+variantIdx : '')}`}>
51
- <ImageComponent src={Array.isArray(value) ? value[0] : value} />
52
- </figure>
53
- }
54
- </div>
55
- }
56
- {error && <ErrorComponent $mode='table'>{error.replace('Product', '')}</ErrorComponent>}
57
- </section>
58
- );
59
- }
60
-
61
- export default ImageEditors;
@@ -1,127 +0,0 @@
1
- import { useCallback } from 'react';
2
- import type { KeyboardEvent, FocusEvent, MouseEvent } from 'react';
3
- import { generateValueTable, debounce, currencyNumber, validateByApproveJs, evGenerateValueMatch } from '../../../../assets/javascripts/function';
4
- import { colorCommonQuantity } from '../../../../assets/javascripts/helper';
5
- import { AdjustedLabel, InfoLabel } from '../../styles';
6
- import type { THeadProps } from '../../../../typeds/shares.typed';
7
- import type { TMouseEvent } from '../../../../typeds/base.typed';
8
- import type { TEditorProps } from '../../typed';
9
- import TextAreaComponent from '../../../textarea';
10
- import InputComponent from '../../../input';
11
-
12
- const InputBareEditors = ({ head, value, evChange, idx, variantIdx, error, content, type, isForceUpdate, setForceUpdate }:Omit<TEditorProps, 'evCloseEditor'>) => {
13
- const eckey = `${head.key}-${idx}${(variantIdx !== undefined ? '-'+variantIdx : '')}`;
14
-
15
- const evCustom = useCallback((valueCustom: string) => {
16
- const keyEl = document.getElementById('cur-key') as HTMLDivElement;
17
- const currentKey = keyEl ? keyEl.innerHTML : '';
18
- if (currentKey && (currentKey === eckey)) {
19
- evChange(head, valueCustom, idx, variantIdx);
20
- }
21
- }, [eckey, head, idx, variantIdx, evChange])
22
-
23
-
24
- const evInput = debounce((currentTarget: HTMLInputElement | HTMLTextAreaElement) => {}, 250);
25
-
26
- const _evBlur = (currentTarget: HTMLInputElement | HTMLTextAreaElement) => {
27
- evCustom(currentTarget.value);
28
- }
29
-
30
- const evKeyUpInput = (e: KeyboardEvent<HTMLInputElement>) => {
31
- if (e.key === 'Enter') {
32
- e.preventDefault();
33
- evCustom(e.currentTarget.value);
34
- return;
35
- }
36
- }
37
-
38
- const evFocusIn = (e: FocusEvent<HTMLInputElement> | MouseEvent<HTMLInputElement>) => {
39
- e.persist();
40
- setTimeout(() => {
41
- const inputEl = e.target as HTMLInputElement;
42
- const value = inputEl.value;
43
- if (value !== '' && value !== null && value !== undefined) {
44
- inputEl && inputEl.focus();
45
- inputEl && inputEl.select();
46
- }
47
- }, 1)
48
- const keyEl = document.getElementById('cur-key') as HTMLDivElement;
49
- keyEl && (keyEl.innerHTML = eckey);
50
- }
51
-
52
- const evClick: TMouseEvent = e => {
53
- e.persist();
54
- const keyEl = document.getElementById('cur-key') as HTMLDivElement;
55
- keyEl && (keyEl.innerHTML = eckey);
56
- }
57
-
58
- const _defaultValue = generateValueTable(value, head.key);
59
- const isSupArr = ['shipping', 'platformRebate'];
60
-
61
- const inputEl = (
62
- head.multiline ?
63
- <TextAreaComponent
64
- name={head.fieldType+'_'+head.key}
65
- defaultValue={value}
66
- evChange={e=> { evInput(e.target) }}
67
- evBlur={e=> { evInput(e.target); _evBlur(e.target) }}
68
- onClick={evClick}
69
- {...error && { isError: true, 'data-tip':error, 'data-place': 'top', 'data-type': 'error' }} /> :
70
- <InputComponent
71
- type={head.typeData === 'Integer' ? 'number' : 'text'}
72
- name={head.fieldType+'_'+head.key}
73
- defaultValue={value}
74
- evChange={e=> { evInput(e.target) }}
75
- evBlur={e=> { evInput(e.target); _evBlur(e.target) }}
76
- onKeyUp={evKeyUpInput}
77
- onClick={evFocusIn}
78
- onFocus={evFocusIn}
79
- isForceUpdate={isForceUpdate}
80
- setForceUpdate={setForceUpdate}
81
- data-qa-id={`mt-input-${(head.name).toLowerCase().replaceAll(' ','-')}-${idx}${(variantIdx !== undefined ? '-'+variantIdx : '')}`}
82
- {...head.typeData === 'Currency' && { mode: 'currency', aliasLabel: isSupArr.includes(head.key) ? '+' : '-' }}
83
- {...head.placeholder && {placeholder: head.placeholder}}
84
- {...error && { isError: true, 'data-tip':error, 'data-place': 'top', 'data-type': 'error' }} />
85
- )
86
-
87
- let el = <div className='master-editor'>{inputEl}</div>;
88
-
89
- if (head?.condition === 'countAdjustment') {
90
- el = (
91
- <div className='master-editor'>
92
- <>
93
- {inputEl}
94
- { (value !== null && (value < content.qtyReserved)) && <InfoLabel style={{ color: 'red' }}>Qty Available'll be minus</InfoLabel> }
95
- </>
96
- </div> );
97
- } else if (head?.condition === 'countOutbound') {
98
- el = (
99
- <div className='master-editor'>
100
- <>
101
- {inputEl}
102
- { (value !== null && (value > content.qtyOnHand)) && <InfoLabel style={{ color: 'red' }}>Qty On Hand'll be minus</InfoLabel> }
103
- </>
104
- </div> );
105
- }
106
-
107
- return (
108
- type === 'create-paymentreceive' ?
109
- <InputComponent
110
- type={head.typeData === 'Integer' ? 'number' : 'text'}
111
- disabled={(content.orderCashless && head.key ==='shipping') || false}
112
- name={head.fieldType+'_'+head.key}
113
- defaultValue={_defaultValue}
114
- evChange={e=> { evInput(e.target) }}
115
- evBlur={e=> { evInput(e.target); _evBlur(e.target) }}
116
- evKeyUp={evKeyUpInput}
117
- onClick={evFocusIn}
118
- onFocus={evFocusIn}
119
- data-qa-id={`mt-input-${(head.name).toLowerCase().replaceAll(' ','-')}-${idx}${(variantIdx !== undefined ? '-'+variantIdx : '')}`}
120
- {...head.typeData === 'Currency' && { mode: 'currency', aliasLabel: isSupArr.includes(head.key) ? '+' : '-' }}
121
- {...head.placeholder && {placeholder: head.placeholder}}
122
- {...error && { isError: true, 'data-tip':error, 'data-place': 'top', 'data-type': 'error' }} /> :
123
- el
124
- );
125
- }
126
-
127
- export default InputBareEditors;
@@ -1,140 +0,0 @@
1
- import { useState, useEffect, useCallback } from 'react';
2
- import type { KeyboardEvent } from 'react';
3
- import ErrorComponent from '../../../error';
4
- import InputComponent from '../../../input';
5
- import TextAreaComponent from '../../../textarea';
6
- import TextComponent from '../../../text';
7
- import { generateValueTable, debounce, currencyNumber } from '../../../../assets/javascripts/function';
8
- import { colorCommonQuantity } from '../../../../assets/javascripts/helper';
9
- import { AdjustedLabel } from '../../styles';
10
- import type { TMouseEvent } from '../../../../typeds/base.typed';
11
- import type { TEditorProps } from '../../typed';
12
-
13
- const InputEditors = ({ head, value, height, evChange, idx, variantIdx, error, evCloseEditor, content }: TEditorProps) => {
14
- const [isEditing, setEdit] = useState<boolean>(false);
15
- const [valueFormState, setValueFormState] = useState<string>(value || '');
16
- const [isFirstLoadEditor, setFirstLoad] = useState<boolean>(true);
17
-
18
- useEffect(() => {
19
- setValueFormState(value);
20
- }, [value])
21
-
22
- const eckey = `${head.key}-${idx}${(variantIdx !== undefined ? '-'+variantIdx : '')}`;
23
-
24
- const evCustom = useCallback((valueCustom: any) => {
25
- const keyEl = document.getElementById('cur-key') as HTMLDivElement;
26
- const currentKey = keyEl ? keyEl.innerHTML : '';
27
- if (currentKey && (currentKey === eckey)) {
28
- evChange(head, valueCustom, idx, variantIdx);
29
- evCloseEditor(() => { setEdit(false) });
30
- }
31
- }, [eckey, head, idx, variantIdx, evChange, evCloseEditor])
32
-
33
- useEffect(() => {
34
- if (!isFirstLoadEditor) {
35
- evCustom(valueFormState);
36
- } else {
37
- setFirstLoad(false);
38
- }
39
- }, [valueFormState, evCustom, isFirstLoadEditor])
40
-
41
- const evClick: TMouseEvent = e => {
42
- e.preventDefault();
43
- const target = e.target as HTMLInputElement;
44
- if (target.closest('.cell-disabled')) {
45
- return false;
46
- }
47
- const keyEl = document.getElementById('cur-key') as HTMLDivElement;
48
- keyEl && (keyEl.innerHTML = eckey);
49
- setEdit(!isEditing);
50
- const cellEl = target.closest('.cell') as HTMLDivElement;
51
- if (!isEditing) {
52
- cellEl && (cellEl.classList.add('cell-editing'));
53
- } else {
54
- cellEl && (cellEl.classList.remove('cell-editing'));
55
- }
56
- setTimeout(() => {
57
- const inputEl = cellEl.querySelector('input');
58
- inputEl && inputEl.focus();
59
- inputEl && inputEl.select();
60
- }, 1)
61
- }
62
-
63
- const evInput = debounce((currentTarget: HTMLInputElement | HTMLTextAreaElement) => {}, 250);
64
-
65
- const _evBlur = (currentTarget: HTMLInputElement | HTMLTextAreaElement) => {
66
- const _value = currentTarget.value;
67
- const isClosed = head.typeData === 'Integer' ? ((valueFormState || _value) ? (parseInt(valueFormState) === parseInt(_value)) : true ) : (valueFormState === _value);
68
- setValueFormState(_value);
69
- if (isClosed) {
70
- evCloseEditor(() => { setEdit(false) });
71
- }
72
- }
73
-
74
- const evKeyUpInput = (e: KeyboardEvent<HTMLInputElement>) => {
75
- if (e.key === 'Enter') {
76
- e.preventDefault();
77
- const _value = e.currentTarget.value;
78
- const isClosed = head.typeData === 'Integer' ? (parseInt(valueFormState) === parseInt(_value)) : (valueFormState === _value);
79
- setValueFormState(_value);
80
- if (isClosed) {
81
- evCloseEditor(() => { setEdit(false) });
82
- }
83
- return;
84
- }
85
- }
86
-
87
- const qaId = `${(head.name).toLowerCase().replaceAll(' ','-')}-${idx}${(variantIdx !== undefined ? '-'+variantIdx : '')}`;
88
- const _valueFormState = (head.typeData === 'Currency' || head.typeData === 'Integer') ? (valueFormState !== null ? valueFormState : '') : (valueFormState ? ((typeof valueFormState === 'string') ? valueFormState.toString().trim() : valueFormState) : '');
89
-
90
- let labelEl = <div data-qa-id={`mt-input-label-${qaId}`}>{generateValueTable(value, head.key)}</div>;
91
- if (head?.condition === 'priceAdjustment' || head?.condition === 'priceAdjustment-sale') {
92
- let adjusted = parseInt(value || 0) - parseInt(content[`${head.key}_base`] || 0);
93
- let adjustedLbl = currencyNumber(adjusted);
94
- if(adjusted > 0) {
95
- adjustedLbl = '+'+ currencyNumber(adjusted);
96
- } else if(adjusted === 0) {
97
- adjustedLbl = '';
98
- }
99
- labelEl = (
100
- <div>
101
- <div data-qa-id={`mt-input-label-${qaId}`}>{generateValueTable(value, head.key)}</div>
102
- { (adjusted !== 0 && adjusted !== null && !error) && <AdjustedLabel style={{ color: colorCommonQuantity(adjusted) }}>{adjustedLbl}</AdjustedLabel> }
103
- </div>
104
- );
105
- }
106
-
107
- return (
108
- !isEditing ?
109
- <section onClick={evClick} className='cell-wrapper'>
110
- {
111
- head.multiline ?
112
- <>
113
- {
114
- (_valueFormState === '' && error) ?
115
- <TextComponent $color='blue' style={{ fontWeight: 500 }}>+ Add</TextComponent> :
116
- <div className='truncate-overflow' data-qa-id={`mt-input-label-${qaId}`} style={{ maxHeight: height ? (parseInt(height as string) - 34) : 'auto' }}>{generateValueTable(value, head.key)}</div>
117
- }
118
- {error && <ErrorComponent $mode='table'>{error}</ErrorComponent>}
119
- </>
120
- :
121
- <>
122
- {
123
- (_valueFormState === '' && error) ?
124
- <TextComponent $color='blue' style={{ fontWeight: 500 }}>+ Add</TextComponent> : labelEl
125
- }
126
- {error && <ErrorComponent $mode='table'>{error}</ErrorComponent>}
127
- </>
128
- }
129
- </section> :
130
- <div className='master-editor'>
131
- {
132
- head.multiline ?
133
- <TextAreaComponent name={head.fieldType+'_'+head.key} defaultValue={valueFormState} evChange={e=> { evInput(e.target) }} evBlur={e=> { evInput(e.target); _evBlur(e.target) }} ></TextAreaComponent> :
134
- <InputComponent type={head.typeData === 'Integer' ? 'number' : 'text'} {...head.typeData === 'Currency' && { mode: 'currency' }} name={head.fieldType+'_'+head.key} defaultValue={valueFormState} evChange={e=> { evInput(e.target) }} evBlur={e=> { evInput(e.target); _evBlur(e.target) }} evKeyUp={evKeyUpInput} data-qa-id={`mt-input-${qaId}`} />
135
- }
136
- </div>
137
- );
138
- }
139
-
140
- export default InputEditors;