Skip to content

Commit 80898ac

Browse files
Merge pull request #219 from okerekechinweotito/fix/change-identifier
Fixes:[T348600] Title not being shown and placeholder text is getting cut
2 parents 85bee50 + 78b6196 commit 80898ac

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

components/Books.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Books extends React.Component {
1919
show: true,
2020
loader: false,
2121
isDuplicate: false,
22-
isValidIdentifier: true,
22+
isInValidIdentifier: false,
2323
IATitle: "",
2424
IAIdentifier: "",
2525
inputDisabled: false,
@@ -36,7 +36,7 @@ class Books extends React.Component {
3636
option: event.target.value,
3737
bookid: "",
3838
isDuplicate: false,
39-
isValidIdentifier: true,
39+
isInValidIdentifier: false,
4040
IATitle: "",
4141
IAIdentifier: "",
4242
inputDisabled: false,
@@ -98,7 +98,7 @@ class Books extends React.Component {
9898
onResetButtonClicked = () => {
9999
this.setState({
100100
isDuplicate: false,
101-
isValidIdentifier: true,
101+
isInValidIdentifier: false,
102102
inputDisabled: false,
103103
IATitle: "",
104104
IAIdentifier: "",
@@ -206,11 +206,10 @@ class Books extends React.Component {
206206
this.setState({
207207
loader: true,
208208
isDuplicate: false,
209-
isValidIdentifier: true,
209+
isInValidIdentifier: false,
210210
});
211211

212212
let url = "";
213-
const isAlphanumericLess50 = /^(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9]{1,50}$/;
214213
switch (this.state.option) {
215214
case "gb":
216215
url = `${host}/check?bookid=${this.state.bookid}&option=${
@@ -229,10 +228,10 @@ class Books extends React.Component {
229228
IATitle: response.titleInIA,
230229
inputDisabled: true,
231230
});
232-
} else if (!isAlphanumericLess50.test(response.IAIdentifier)) {
231+
} else if (response.isInValidIdentifier) {
233232
this.setState({
234-
isValidIdentifier: false,
235-
IATitle: response.IAIdentifier,
233+
isInValidIdentifier: true,
234+
IATitle: response.titleInIA,
236235
inputDisabled: true,
237236
});
238237
} else {
@@ -326,10 +325,10 @@ class Books extends React.Component {
326325
IATitle: response.titleInIA,
327326
inputDisabled: true,
328327
});
329-
} else if (!isAlphanumericLess50.test(response.IAIdentifier)) {
328+
} else if (response.isInValidIdentifier) {
330329
this.setState({
331-
isValidIdentifier: false,
332-
IATitle: response.IAIdentifier,
330+
isInValidIdentifier: true,
331+
IATitle: response.titleInIA,
333332
inputDisabled: true,
334333
});
335334
} else {
@@ -362,10 +361,10 @@ class Books extends React.Component {
362361
IATitle: response.titleInIA,
363362
inputDisabled: true,
364363
});
365-
} else if (!isAlphanumericLess50.test(response.IAIdentifier)) {
364+
} else if (response.isInValidIdentifier) {
366365
this.setState({
367-
isValidIdentifier: false,
368-
IATitle: response.IAIdentifier,
366+
isInValidIdentifier: true,
367+
IATitle: response.titleInIA,
369368
inputDisabled: true,
370369
});
371370
} else {
@@ -423,7 +422,7 @@ class Books extends React.Component {
423422
/>
424423
) : null}
425424

426-
{this.state.isValidIdentifier === false ? (
425+
{this.state.isInValidIdentifier === true ? (
427426
<ChangeIdentifier
428427
description={
429428
<>
@@ -434,7 +433,7 @@ class Books extends React.Component {
434433
(0-9).
435434
</>
436435
}
437-
inputPlaceholder="Enter a valid Identifier that is less than 50 characters and Alphanumeric"
436+
inputPlaceholder="Enter valid identifier"
438437
onIdentifierChange={(event) =>
439438
this.setState({ IAIdentifier: event.target.value })
440439
}
@@ -448,7 +447,7 @@ class Books extends React.Component {
448447
Submit
449448
</button>
450449
{this.state.isDuplicate === true ||
451-
this.state.isValidIdentifier === false ? (
450+
this.state.isInValidIdentifier === true ? (
452451
<button
453452
onClick={this.onResetButtonClicked}
454453
style={{ marginLeft: 40 }}

server.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ app
368368
});
369369

370370
let GBdetails = {};
371+
const isAlphanumericLess50 = /^[a-zA-Z0-9]{1,50}$/;
371372
server.get("/check", async (req, res) => {
372373
const { bookid, option, email, userName, IAtitle } = req.query;
373374
emailaddr = email;
@@ -387,7 +388,12 @@ app
387388
IAtitle.trim() !== ""
388389
? replaceTitle(IAtitle.trim())
389390
: replaceTitle(data.volumeInfo.title);
390-
if ((await checkIfFileExistsAtIA(titleInIA)) === true) {
391+
if (isAlphanumericLess50.test(titleInIA) === false) {
392+
res.send({
393+
isInValidIdentifier: true,
394+
titleInIA,
395+
});
396+
} else if ((await checkIfFileExistsAtIA(titleInIA)) === true) {
391397
res.send({
392398
isDuplicate: true,
393399
titleInIA,
@@ -431,6 +437,11 @@ app
431437
error: true,
432438
message: "Not able to fetch title.",
433439
});
440+
} else if (isAlphanumericLess50.test(titleInIA) === false) {
441+
res.send({
442+
isInValidIdentifier: true,
443+
titleInIA,
444+
});
434445
} else {
435446
if ((await checkIfFileExistsAtIA(titleInIA)) === true) {
436447
res.send({
@@ -478,7 +489,12 @@ app
478489
IAtitle.trim() !== ""
479490
? replaceTitle(IAtitle.trim())
480491
: replaceTitle(name);
481-
if ((await checkIfFileExistsAtIA(titleInIA)) === true) {
492+
if (isAlphanumericLess50.test(titleInIA) === false) {
493+
res.send({
494+
isInValidIdentifier: true,
495+
titleInIA,
496+
});
497+
} else if ((await checkIfFileExistsAtIA(titleInIA)) === true) {
482498
res.send({
483499
isDuplicate: true,
484500
titleInIA,

0 commit comments

Comments
 (0)