Skip to content
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
33 changes: 16 additions & 17 deletions components/Books.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Books extends React.Component {
show: true,
loader: false,
isDuplicate: false,
isValidIdentifier: true,
isInValidIdentifier: false,
IATitle: "",
IAIdentifier: "",
inputDisabled: false,
Expand All @@ -36,7 +36,7 @@ class Books extends React.Component {
option: event.target.value,
bookid: "",
isDuplicate: false,
isValidIdentifier: true,
isInValidIdentifier: false,
IATitle: "",
IAIdentifier: "",
inputDisabled: false,
Expand Down Expand Up @@ -98,7 +98,7 @@ class Books extends React.Component {
onResetButtonClicked = () => {
this.setState({
isDuplicate: false,
isValidIdentifier: true,
isInValidIdentifier: false,
inputDisabled: false,
IATitle: "",
IAIdentifier: "",
Expand Down Expand Up @@ -206,11 +206,10 @@ class Books extends React.Component {
this.setState({
loader: true,
isDuplicate: false,
isValidIdentifier: true,
isInValidIdentifier: false,
});

let url = "";
const isAlphanumericLess50 = /^(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9]{1,50}$/;
switch (this.state.option) {
case "gb":
url = `${host}/check?bookid=${this.state.bookid}&option=${
Expand All @@ -229,10 +228,10 @@ class Books extends React.Component {
IATitle: response.titleInIA,
inputDisabled: true,
});
} else if (!isAlphanumericLess50.test(response.IAIdentifier)) {
} else if (response.isInValidIdentifier) {
this.setState({
isValidIdentifier: false,
IATitle: response.IAIdentifier,
isInValidIdentifier: true,
IATitle: response.titleInIA,
inputDisabled: true,
});
} else {
Expand Down Expand Up @@ -326,10 +325,10 @@ class Books extends React.Component {
IATitle: response.titleInIA,
inputDisabled: true,
});
} else if (!isAlphanumericLess50.test(response.IAIdentifier)) {
} else if (response.isInValidIdentifier) {
this.setState({
isValidIdentifier: false,
IATitle: response.IAIdentifier,
isInValidIdentifier: true,
IATitle: response.titleInIA,
inputDisabled: true,
});
} else {
Expand Down Expand Up @@ -362,10 +361,10 @@ class Books extends React.Component {
IATitle: response.titleInIA,
inputDisabled: true,
});
} else if (!isAlphanumericLess50.test(response.IAIdentifier)) {
} else if (response.isInValidIdentifier) {
this.setState({
isValidIdentifier: false,
IATitle: response.IAIdentifier,
isInValidIdentifier: true,
IATitle: response.titleInIA,
inputDisabled: true,
});
} else {
Expand Down Expand Up @@ -423,7 +422,7 @@ class Books extends React.Component {
/>
) : null}

{this.state.isValidIdentifier === false ? (
{this.state.isInValidIdentifier === true ? (
<ChangeIdentifier
description={
<>
Expand All @@ -434,7 +433,7 @@ class Books extends React.Component {
(0-9).
</>
}
inputPlaceholder="Enter a valid Identifier that is less than 50 characters and Alphanumeric"
inputPlaceholder="Enter valid identifier"
onIdentifierChange={(event) =>
this.setState({ IAIdentifier: event.target.value })
}
Expand All @@ -448,7 +447,7 @@ class Books extends React.Component {
Submit
</button>
{this.state.isDuplicate === true ||
this.state.isValidIdentifier === false ? (
this.state.isInValidIdentifier === true ? (
<button
onClick={this.onResetButtonClicked}
style={{ marginLeft: 40 }}
Expand Down
20 changes: 18 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ app
});

let GBdetails = {};
const isAlphanumericLess50 = /^[a-zA-Z0-9]{1,50}$/;
server.get("/check", async (req, res) => {
const { bookid, option, email, userName, IAtitle } = req.query;
emailaddr = email;
Expand All @@ -387,7 +388,12 @@ app
IAtitle.trim() !== ""
? replaceTitle(IAtitle.trim())
: replaceTitle(data.volumeInfo.title);
if ((await checkIfFileExistsAtIA(titleInIA)) === true) {
if (isAlphanumericLess50.test(titleInIA) === false) {
res.send({
isInValidIdentifier: true,
titleInIA,
});
} else if ((await checkIfFileExistsAtIA(titleInIA)) === true) {
res.send({
isDuplicate: true,
titleInIA,
Expand Down Expand Up @@ -431,6 +437,11 @@ app
error: true,
message: "Not able to fetch title.",
});
} else if (isAlphanumericLess50.test(titleInIA) === false) {
res.send({
isInValidIdentifier: true,
titleInIA,
});
} else {
if ((await checkIfFileExistsAtIA(titleInIA)) === true) {
res.send({
Expand Down Expand Up @@ -478,7 +489,12 @@ app
IAtitle.trim() !== ""
? replaceTitle(IAtitle.trim())
: replaceTitle(name);
if ((await checkIfFileExistsAtIA(titleInIA)) === true) {
if (isAlphanumericLess50.test(titleInIA) === false) {
res.send({
isInValidIdentifier: true,
titleInIA,
});
} else if ((await checkIfFileExistsAtIA(titleInIA)) === true) {
res.send({
isDuplicate: true,
titleInIA,
Expand Down