Skip to content

Commit

Permalink
UICIRC-1121 - Add preliminary changes with debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Terala-Priyanka committed Dec 9, 2024
1 parent ff7a54f commit e9d1e60
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 82 deletions.
1 change: 1 addition & 0 deletions src/settings/PatronNotices/PatronNoticeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ const PatronNoticeForm = (props) => {
printOnly={printOnly}
category={category}
locale={locale}
template={values?.localizedTemplates}
/>
</Accordion>
</AccordionSet>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { memo } from 'react';
import Proptypes from 'prop-types';
import { injectIntl } from 'react-intl';
import { Field } from 'react-final-form';
Expand All @@ -19,91 +19,101 @@ import {
import { patronNoticeCategories } from '../../../../../constants';
import { validateUniqueNameById } from '../../../../utils/utils';

const PatronNoticeAboutSection = ({ initialValues, okapi, intl }) => {
const { formatMessage } = intl;
const categoryOptions = patronNoticeCategories.map(({ label, id }) => ({
label: formatMessage({ id: label }),
value: id,
}));
const isActive = initialValues && initialValues.active;
const PatronNoticeAboutSection = memo(
({ initialValues, okapi, intl }) => {
const { formatMessage } = intl;
const categoryOptions = patronNoticeCategories.map(({ label, id }) => ({
label: formatMessage({ id: label }),
value: id,
}));
const isActive = initialValues && initialValues.active;

const getTemplatesByName = (name) => {
return fetch(`${okapi.url}/templates?query=(name=="${name}")`,
{
...getHeaderWithCredentials(okapi)
});
};
const getTemplatesByName = (name) => {
return fetch(`${okapi.url}/templates?query=(name=="${name}")`,
{
...getHeaderWithCredentials(okapi)
});
};

const validateName = memoize((name) => (
validateUniqueNameById({
currentName: name,
previousId: initialValues.id,
getByName: getTemplatesByName,
selector: 'templates',
errorKey: 'settings.patronNotices.errors.nameExists',
})
));
const validateName = memoize((name) => (
validateUniqueNameById({
currentName: name,
previousId: initialValues.id,
getByName: getTemplatesByName,
selector: 'templates',
errorKey: 'settings.patronNotices.errors.nameExists',
})
));

return (
<div data-testid="patronNoticeAboutSection">
<Row>
<Col
xs={12}
data-test-patron-notice-template-name
>
<Field
data-testid="patronNoticesNoticeName"
label={formatMessage({ id: 'ui-circulation.settings.patronNotices.notice.name' })}
name="name"
required
id="input-patron-notice-name"
autoFocus
component={TextField}
validate={validateName}
/>
</Col>
</Row>
<Row>
<Col xs={12}>
<Field
data-testid="patronNoticesNoticeActive"
label={formatMessage({ id:'ui-circulation.settings.patronNotices.notice.active' })}
name="active"
id="input-patron-notice-active"
component={Checkbox}
defaultChecked={isActive}
/>
</Col>
</Row>
<br />
<Row>
<Col xs={12}>
<Field
data-testid="patronNoticesNoticeDescription"
label={formatMessage({ id:'ui-circulation.settings.patronNotices.notice.description' })}
name="description"
id="input-patron-notice-description"
component={TextArea}
/>
</Col>
</Row>
<Row>
<Col xs={12}>
<div data-test-template-category>
return (
<div data-testid="patronNoticeAboutSection">
<Row>
<Col
xs={12}
data-test-patron-notice-template-name
>
<Field
data-testid="patronNoticesNoticeCategory"
label={formatMessage({ id:'ui-circulation.settings.patronNotices.notice.category' })}
name="category"
component={Select}
fullWidth
dataOptions={categoryOptions}
data-testid="patronNoticesNoticeName"
label={formatMessage({ id: 'ui-circulation.settings.patronNotices.notice.name' })}
name="name"
required
id="input-patron-notice-name"
autoFocus
component={TextField}
validate={validateName}
/>
</div>
</Col>
</Row>
</div>
);
};
</Col>
</Row>
<Row>
<Col xs={12}>
<Field
data-testid="patronNoticesNoticeActive"
label={formatMessage({ id:'ui-circulation.settings.patronNotices.notice.active' })}
name="active"
id="input-patron-notice-active"
component={Checkbox}
defaultChecked={isActive}
/>
</Col>
</Row>
<br />
<Row>
<Col xs={12}>
<Field
data-testid="patronNoticesNoticeDescription"
label={formatMessage({ id:'ui-circulation.settings.patronNotices.notice.description' })}
name="description"
id="input-patron-notice-description"
component={TextArea}
/>
</Col>
</Row>
<Row>
<Col xs={12}>
<div data-test-template-category>
<Field
data-testid="patronNoticesNoticeCategory"
label={formatMessage({ id:'ui-circulation.settings.patronNotices.notice.category' })}
name="category"
component={Select}
fullWidth
dataOptions={categoryOptions}
/>
</div>
</Col>
</Row>
</div>
);
},
(prevProps, newProps) => {
const { prevId, prevActive } = prevProps.initialValues;
const { newId, newActive } = newProps.initialValues;
console.log('PatronNoticeAboutSection are initial values same ', prevId === newId && prevActive === newActive);

Check warning on line 111 in src/settings/PatronNotices/components/EditSections/PatronNoticeAboutSection/PatronNoticeAboutSection.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Unexpected console statement

return prevId === newId && prevActive === newActive;
}
);

PatronNoticeAboutSection.propTypes = {
initialValues: Proptypes.object.isRequired,
okapi: Proptypes.object.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import { TemplateEditor } from '@folio/stripes-template-editor';
import getTokens from '../../../tokens';
import TokensList from '../../../TokensList';

const PatronNoticeEmailSection = ({ category, locale, printOnly }) => {
const PatronNoticeEmailSection = ({ template, category, locale, printOnly }) => {
const tokens = getTokens(locale);

console.log('PatronNoticeEmailSection template ', template, template?.en?.body);

Check warning on line 20 in src/settings/PatronNotices/components/EditSections/PatronNoticeEmailSection/PatronNoticeEmailSection.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Unexpected console statement

return (
<div data-testid="emailAccordionContent">
<Row>
Expand Down Expand Up @@ -70,5 +72,6 @@ PatronNoticeEmailSection.propTypes = {
category: PropTypes.string,
locale: PropTypes.string,
printOnly: PropTypes.bool,
template: PropTypes.object,
};
export default PatronNoticeEmailSection;

0 comments on commit e9d1e60

Please sign in to comment.