Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BB-764: Unified form ISBNs bug #1083

Merged
merged 3 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/client/unified-form/cover-tab/isbn-field.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import {ISBNDispatchProps, ISBNProps, ISBNStateProps, RInputEvent, State} from '../interface/type';
import {ISBNDispatchProps, ISBNProps, ISBNStateProps, RInputEvent, State, dispatchResultProps} from '../interface/type';
import {addOtherISBN, removeIdentifierRow} from '../../entity-editor/identifier-editor/actions';
import {debouncedUpdateISBNValue, updateAutoISBN, updateISBNType} from './action';
import {isbn10To13, isbn13To10} from '../../../common/helpers/utils';
import {FormCheck} from 'react-bootstrap';
import NameField from '../../entity-editor/common/name-field';
import React from 'react';
import {addOtherISBN} from '../../entity-editor/identifier-editor/actions';
import {connect} from 'react-redux';


export function ISBNField(props:ISBNProps) {
const {value, type, onChange, autoISBN, onAutoISBNChange} = props;
const onChangeHandler = React.useCallback((event:RInputEvent) => onChange(event.target.value, autoISBN), [onChange, autoISBN]);
const onAutoISBNChangeHandler = React.useCallback(
(event:RInputEvent) => onAutoISBNChange(event.target.checked) && onChange(value, event.target.checked), [onAutoISBNChange, onChange, value]
);
const onAutoISBNChangeHandler = React.useCallback((event:RInputEvent) => {
onAutoISBNChange(event.target.checked);
onChange(value, event.target.checked);
}, [onAutoISBNChange, onChange, value]);
let checkboxLabel = 'Automatically add ISBN';
if (type) {
checkboxLabel += type === 10 ? `13 (${isbn10To13(value)})` : `10 (${isbn13To10(value)})`;
Expand Down Expand Up @@ -52,6 +53,7 @@ function mapStateToProps(rootState:State):ISBNStateProps {
}

function mapDispatchToProps(dispatch):ISBNDispatchProps {
let autoAddedISBN:dispatchResultProps|null;
function onChange(value:string, autoISBN = false) {
const isbn10rgx = new
RegExp('^(?:ISBN(?:-10)?:?●)?(?=[0-9X]{10}$|(?=(?:[0-9]+[-●]){3})[-●0-9X]{13}$)[0-9]{1,5}[-●]?[0-9]+[-●]?[0-9]+[-●]?[0-9X]$');
Expand All @@ -76,12 +78,19 @@ function mapDispatchToProps(dispatch):ISBNDispatchProps {
}
dispatch(updateISBNType(type));
if (autoISBN && otherISBN.type) {
dispatch(addOtherISBN(otherISBN.type, otherISBN.value));
autoAddedISBN = dispatch(addOtherISBN(otherISBN.type, otherISBN.value));
}
dispatch(debouncedUpdateISBNValue(value));
}
return {
onAutoISBNChange: (checked:boolean) => dispatch(updateAutoISBN(checked)),
onAutoISBNChange: (checked:boolean) => {
dispatch(updateAutoISBN(checked));
if(autoAddedISBN){
dispatch(removeIdentifierRow(autoAddedISBN.payload.rowId));
autoAddedISBN=null;
}
return;
},
onChange
};
}
Expand Down
9 changes: 9 additions & 0 deletions src/client/unified-form/interface/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ export type ISBNDispatchProps = {
};
export type ISBNProps = ISBNStateProps & ISBNDispatchProps;

export type dispatchResultProps = {
payload: {
rowId: number,
type:number,
value:string
},
type: string
}

export type EntitySelect = {
text:string,
id:string
Expand Down
Loading