Skip to content

Commit

Permalink
Merge pull request #299 from vietredweb/Issue-298
Browse files Browse the repository at this point in the history
fixes #298 Fix Image, Youtube Field layout
  • Loading branch information
lunguyenhat authored Jun 17, 2023
2 parents 05f4a8e + 7a8b921 commit 76fd7ce
Show file tree
Hide file tree
Showing 24 changed files with 431 additions and 26 deletions.
24 changes: 24 additions & 0 deletions src/components/Fields/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const FieldsList = observer(
let selectedValue = '';
if (
field[PIM_FIELD_DETAIL_FIELD_KEY.TYPE] === FORM_FIELD_TYPE.SELECTION ||
field[PIM_FIELD_DETAIL_FIELD_KEY.TYPE] === FORM_FIELD_TYPE.CONTENT_TYPE ||
field[PIM_FIELD_DETAIL_FIELD_KEY.TYPE] === FORM_FIELD_TYPE.CATEGORY_RELATED ||
field[PIM_FIELD_DETAIL_FIELD_KEY.TYPE] === FORM_FIELD_TYPE.ITEM_RELATED ||
field[PIM_FIELD_DETAIL_FIELD_KEY.TYPE] === FORM_FIELD_TYPE.RADIO ||
Expand Down Expand Up @@ -176,6 +177,7 @@ const FieldsList = observer(
handleChange: (data) => {
if (
field[PIM_FIELD_DETAIL_FIELD_KEY.TYPE] === FORM_FIELD_TYPE.SELECTION ||
field[PIM_FIELD_DETAIL_FIELD_KEY.TYPE] === FORM_FIELD_TYPE.CONTENT_TYPE ||
field[PIM_FIELD_DETAIL_FIELD_KEY.TYPE] === FORM_FIELD_TYPE.CATEGORY_RELATED ||
field[PIM_FIELD_DETAIL_FIELD_KEY.TYPE] === FORM_FIELD_TYPE.ITEM_RELATED
) {
Expand All @@ -202,6 +204,27 @@ const FieldsList = observer(
[PIM_FIELD_DETAIL_FIELD_KEY.CUSTOM_FIELDS],
{ [field[PIM_FIELD_DETAIL_FIELD_KEY.FIELD_CODE]]: data ?? '' }
);
} else if (field[PIM_FIELD_DETAIL_FIELD_KEY.TYPE] === FORM_FIELD_TYPE.YOUTUBE) {
this.props.detailViewModal.handleFormPropsData(
[PIM_FIELD_DETAIL_FIELD_KEY.CUSTOM_FIELDS],
{
[field[PIM_FIELD_DETAIL_FIELD_KEY.FIELD_CODE]]: data?.length
? data
: [{ value: '' }],
}
);
} else if (
field[PIM_FIELD_DETAIL_FIELD_KEY.TYPE] === FORM_FIELD_TYPE.URL ||
field[PIM_FIELD_DETAIL_FIELD_KEY.TYPE] === FORM_FIELD_TYPE.URL_EXTENDED
) {
this.props.detailViewModal.handleFormPropsData(
[PIM_FIELD_DETAIL_FIELD_KEY.CUSTOM_FIELDS],
{
[field[PIM_FIELD_DETAIL_FIELD_KEY.FIELD_CODE]]: data?.length
? data
: [{ url: '', title: '' }],
}
);
} else {
this.props.detailViewModal.handleFormPropsData(
[PIM_FIELD_DETAIL_FIELD_KEY.CUSTOM_FIELDS],
Expand All @@ -223,6 +246,7 @@ const FieldsList = observer(
(field[PIM_FIELD_DETAIL_FIELD_KEY.TYPE] === FORM_FIELD_TYPE.IMAGE ||
field[PIM_FIELD_DETAIL_FIELD_KEY.TYPE] === FORM_FIELD_TYPE.LIST ||
field[PIM_FIELD_DETAIL_FIELD_KEY.TYPE] === FORM_FIELD_TYPE.SELECTION ||
field[PIM_FIELD_DETAIL_FIELD_KEY.TYPE] === FORM_FIELD_TYPE.CONTENT_TYPE ||
field[PIM_FIELD_DETAIL_FIELD_KEY.TYPE] === FORM_FIELD_TYPE.CATEGORY_RELATED ||
field[PIM_FIELD_DETAIL_FIELD_KEY.TYPE] === FORM_FIELD_TYPE.ITEM_RELATED) &&
field[PIM_FIELD_DETAIL_FIELD_KEY.PARAMS]?.multiple === '1',
Expand Down
1 change: 0 additions & 1 deletion src/components/Form/FormCheckbox/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const FormCheckbox = ({ field }) => {
}, [selectedValue]);

const handleChange = (data) => {
console.log('data', data);
if (data.target.checked) {
setSelectedValue((current) => [...current, data.target.value]);
} else {
Expand Down
14 changes: 12 additions & 2 deletions src/components/Form/FormImage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ const FormImage = ({ field, ...props }) => {
>
<SVGComponent url="/assets/images/delete.svg" className={'bg-danger'} />
</div>
<ComponentImage src={JSON.parse(item)?.download_url} alt={field.value} />
<ComponentImage
src={JSON.parse(item)?.download_url}
alt={field.value}
className="h-100"
wrapperClassName="h-100"
/>
</div>
</Ratio>
</Col>
Expand Down Expand Up @@ -117,7 +122,12 @@ const FormImage = ({ field, ...props }) => {
>
<SVGComponent url="/assets/images/delete.svg" className={'bg-danger'} />
</div>
<ComponentImage src={file[0]?.download_url} alt={field.value} />
<ComponentImage
src={file[0]?.download_url}
alt={field.value}
className="h-100"
wrapperClassName="h-100"
/>
</>
)
: null}
Expand Down
88 changes: 88 additions & 0 deletions src/components/Form/FormUrl/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* @copyright Copyright (C) 2022 AesirX. All rights reserved.
* @license GNU General Public License version 3, see LICENSE.
*/

import React, { useState } from 'react';
import { Button, Col, Row } from 'react-bootstrap';
import './index.scss';
import { withTranslation } from 'react-i18next';
import Input from '../Input';
import { SVGComponent } from 'aesirx-uikit';
const FormUrl = ({ field, ...props }) => {
const { t } = props;
const [listOptions, setListOptions] = useState(
field?.getValueSelected?.length ? field?.getValueSelected : [{ url: '', title: '' }]
);
return (
<>
{listOptions?.map((option, index) => {
return (
<div key={`${index}`} className="position-relative">
<Row className="mt-16 gx-24">
<Col xs={4}>
<Input
key={index + option?.url}
field={{
key: index + option?.url,
getValueSelected: option?.url,
classNameInput: 'fs-14',
placeholder: 'Url',
handleChange: (data) => {
listOptions[index] = { ...listOptions[index], url: data.target.value };
setListOptions(listOptions);
field.handleChange(listOptions);
},
}}
/>
</Col>
<Col xs={8}>
<div className="d-flex">
<div className="w-100">
<Input
key={index + option?.title}
field={{
key: index + option?.title,
getValueSelected: option?.title,
classNameInput: 'fs-14',
placeholder: 'Title',
handleChange: (data) => {
listOptions[index] = { ...listOptions[index], title: data.target.value };
setListOptions(listOptions);
field.handleChange(listOptions);
},
}}
/>
</div>
<div
className="border-1 rounded-1 d-flex align-items-center justify-content-center ms-24 px-8px cursor-pointer"
onClick={() => {
let array = [...listOptions];
array.splice(index, 1);
setListOptions(array);
field.handleChange(array);
}}
>
<SVGComponent url="/assets/images/cancel.svg" className={'bg-danger'} />
</div>
</div>
</Col>
</Row>
</div>
);
})}
<Button
variant={`light`}
className={`px-24 py-10 fw-semibold d-flex align-items-center rounded-1 border border-success border-da-1 mt-16`}
onClick={() => {
setListOptions([...listOptions, { url: '', title: '' }]);
}}
>
<SVGComponent url="/assets/images/plus.svg" className={`me-15`} />
{t('txt_add')}
</Button>
</>
);
};

export default withTranslation()(FormUrl);
15 changes: 15 additions & 0 deletions src/components/Form/FormUrl/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* @copyright Copyright (C) 2022 AesirX. All rights reserved.
* @license GNU General Public License version 3, see LICENSE.
*/

@import '../../../scss/utils/bootstrap.scss';

.input-format {
position: absolute;
top: 1px;
right: 0;
width: 60px;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
72 changes: 72 additions & 0 deletions src/components/Form/FormYoutube/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* @copyright Copyright (C) 2022 AesirX. All rights reserved.
* @license GNU General Public License version 3, see LICENSE.
*/

import React, { useState } from 'react';
import { Button, Col, Row } from 'react-bootstrap';
import './index.scss';
import { withTranslation } from 'react-i18next';
import Input from '../Input';
import { SVGComponent } from 'aesirx-uikit';
const FormYoutube = ({ field, ...props }) => {
const { t } = props;
const [listOptions, setListOptions] = useState(
field?.getValueSelected?.length ? field?.getValueSelected : ['']
);
return (
<>
{listOptions?.map((option, index) => {
return (
<div key={`${index}`} className="position-relative">
<Row className="mt-16 gx-24">
<Col xs={12}>
<div className="d-flex">
<div className="w-100">
<Input
key={index + option?.value}
field={{
key: index + option?.value,
getValueSelected: option?.value,
classNameInput: 'fs-14',
placeholder: 'Value',
handleChange: (data) => {
listOptions[index] = { value: data.target.value };
setListOptions(listOptions);
field.handleChange(listOptions);
},
}}
/>
</div>
<div
className="border-1 rounded-1 d-flex align-items-center justify-content-center ms-24 px-8px cursor-pointer"
onClick={() => {
let array = [...listOptions];
array.splice(index, 1);
setListOptions(array);
field.handleChange(array);
}}
>
<SVGComponent url="/assets/images/cancel.svg" className={'bg-danger'} />
</div>
</div>
</Col>
</Row>
</div>
);
})}
<Button
variant={`light`}
className={`px-24 py-10 fw-semibold d-flex align-items-center rounded-1 border border-success border-da-1 mt-16`}
onClick={() => {
setListOptions([...listOptions, '']);
}}
>
<SVGComponent url="/assets/images/plus.svg" className={`me-15`} />
{t('txt_add')}
</Button>
</>
);
};

export default withTranslation()(FormYoutube);
15 changes: 15 additions & 0 deletions src/components/Form/FormYoutube/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* @copyright Copyright (C) 2022 AesirX. All rights reserved.
* @license GNU General Public License version 3, see LICENSE.
*/

@import '../../../scss/utils/bootstrap.scss';

.input-format {
position: absolute;
top: 1px;
right: 0;
width: 60px;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
7 changes: 4 additions & 3 deletions src/components/Form/Input/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ const Input = ({ field, ...props }) => {
const { t } = props;
const handleChange = (e) => {
if (Object.prototype.hasOwnProperty.call(field, 'handleChange')) {
e.target.value = field.maxLength
? e.target.value.normalize('NFKC').slice(0, field.maxLength)
: e.target.value.normalize('NFKC');
e.target.value =
field.maxLength && field.maxLength !== '0'
? e.target.value.normalize('NFKC').slice(0, field.maxLength)
: e.target.value.normalize('NFKC');
field.handleChange(e);
}
};
Expand Down
5 changes: 5 additions & 0 deletions src/constants/FormFieldType.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ const FORM_FIELD_TYPE = {
REDITEM_CATEGORY: 'reditem.category',
RICATEGORIESTREE: 'ricategoriestree',
REDITEM_CUSTOMFIELD: 'reditem.customfield',
CONTENT_TYPE: 'content_type',
ITEM_RELATED_INFO: 'item_related_info',
YOUTUBE: 'youtube',
URL: 'url',
URL_EXTENDED: 'url_extended',
};

const FORMAT_DATE = 'dd MMM, yyyy';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const CategoryInformation = observer(
}

async componentDidMount() {
this.context.categoryListViewModel.handleFilter({ "list[limit]": 9999 });
this.context.categoryListViewModel.handleFilter({ 'list[limit]': 9999 });
this.context.categoryListViewModel.initializeDataCustom();
this.utilsListViewModel.getListContentType({ 'filter[type]': 'category' });
}
Expand All @@ -48,7 +48,9 @@ const CategoryInformation = observer(
PIM_CATEGORY_DETAIL_FIELD_KEY.ALIAS
],
className: 'col-lg-12',
placeholder: this.viewModel.aliasChange ? this.viewModel.aliasChange : t('txt_type'),
placeholder: this.viewModel.aliasChange
? this.viewModel.aliasChange
: t('txt_type_category_alias'),
handleChange: (event) => {
this.viewModel.handleFormPropsData(
PIM_CATEGORY_DETAIL_FIELD_KEY.ALIAS,
Expand Down Expand Up @@ -101,6 +103,7 @@ const CategoryInformation = observer(
notify(this.props.t('txt_product_type_change_warning'), 'warn');
}
},
placeholder: t('txt_select_category'),
className: 'col-lg-12',
},
{
Expand Down Expand Up @@ -145,6 +148,7 @@ const CategoryInformation = observer(
data.value
);
},
placeholder: t('txt_select_category'),
className: 'col-lg-12',
},
{
Expand Down Expand Up @@ -173,6 +177,7 @@ const CategoryInformation = observer(
convertData
);
},
placeholder: t('txt_select_category'),
isMulti: true,
className: 'col-lg-12',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class CategoryDetailViewModel {
}
}
};

handleProductType = (value) => {
runInAction(() => {
this.productType = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const DebtorGroupInformation = observer(
PIM_DEBTOR_GROUP_DETAIL_FIELD_KEY.CUSTOM_FIELDS
]?.code,
className: 'col-lg-12',
placeholder: t('txt_type'),
placeholder: t('txt_type_debtor_code'),
handleChange: (event) => {
this.viewModel.handleFormPropsData(
[PIM_DEBTOR_GROUP_DETAIL_FIELD_KEY.CUSTOM_FIELDS],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const FieldGroupInformation = observer(
this.viewModel.fieldGroupDetailViewModel.formPropsData[
PIM_FIELD_GROUP_DETAIL_FIELD_KEY.ALIAS
],
placeholder: this.viewModel.aliasChange ? this.viewModel.aliasChange : t('txt_type'),
placeholder: this.viewModel.aliasChange
? this.viewModel.aliasChange
: t('txt_type_field_group_alias'),
handleChange: (data) => {
this.viewModel.handleFormPropsData(
PIM_FIELD_GROUP_DETAIL_FIELD_KEY.ALIAS,
Expand Down
Loading

0 comments on commit 76fd7ce

Please sign in to comment.