Skip to content

Commit

Permalink
Merge pull request #1083 from insane-22/unifiedForm-isbn
Browse files Browse the repository at this point in the history
BB-764: Unified form ISBNs bug
  • Loading branch information
MonkeyDo authored May 30, 2024
2 parents 091006f + 05870c8 commit b2ab1c9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
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

0 comments on commit b2ab1c9

Please sign in to comment.