From 57ec8e5e5d900d3dc2bac4377e83b2eb2657daf6 Mon Sep 17 00:00:00 2001 From: Sharon Mwenda Date: Wed, 11 Oct 2023 10:27:55 +0300 Subject: [PATCH 1/4] fix:bug in upload book --- components/Books.js | 7 ++++++- pages/api/auth/[...nextauth].js | 13 +++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/components/Books.js b/components/Books.js index c3b0ce8..0785b14 100644 --- a/components/Books.js +++ b/components/Books.js @@ -220,6 +220,7 @@ class Books extends React.Component { fetch(url) .then((response) => response.json()) .then(async (response) => { + console.log("Response from the server:", response); this.setState({ loader: false, }); @@ -235,6 +236,7 @@ class Books extends React.Component { IATitle: response.IAIdentifier, inputDisabled: true, }); + console.log(response.IAIdentifier); } else { if (response.error) { Swal("Error!", response.message, "error"); @@ -317,6 +319,7 @@ class Books extends React.Component { fetch(url) .then((res) => res.json()) .then((response) => { + console.log("Response from the server:", response); this.setState({ loader: false, }); @@ -327,9 +330,11 @@ class Books extends React.Component { inputDisabled: true, }); } else if (!isAlphanumericLess50.test(response.IAIdentifier)) { + console.log("IAIdentifier:", response.IAIdentifier); this.setState({ isValidIdentifier: false, IATitle: response.IAIdentifier, + //IATitle: response.message, inputDisabled: true, }); } else { @@ -434,7 +439,7 @@ class Books extends React.Component { (0-9). } - inputPlaceholder="Enter a valid Identifier that is less than 50 characters and Alphanumeric" + inputPlaceholder="Enter a valid Identifier" onIdentifierChange={(event) => this.setState({ IAIdentifier: event.target.value }) } diff --git a/pages/api/auth/[...nextauth].js b/pages/api/auth/[...nextauth].js index ce47fd1..debfaa3 100644 --- a/pages/api/auth/[...nextauth].js +++ b/pages/api/auth/[...nextauth].js @@ -7,8 +7,17 @@ export const authOptions = { providers: [ WikimediaProvider({ clientId: process.env.WIKIMEDIA_CLIENT_ID, - clientSecret: process.env.WIKIMEDIA_CLIENT_SECRET - }) + clientSecret: process.env.WIKIMEDIA_CLIENT_SECRET, + authorization: { + url: + "https://meta.wikimedia.beta.wmflabs.org/w/rest.php/oauth2/authorize", + params: { scope: "" }, + }, + token: + "https://meta.wikimedia.beta.wmflabs.org//w/rest.php/oauth2/access_token", + userinfo: + "https://meta.wikimedia.beta.wmflabs.org//w/rest.php/oauth2/resource/profile", + }), ], session: { jwt: true, From d3d5eaf57eabf5bf495ff6627a534204bbac4ab9 Mon Sep 17 00:00:00 2001 From: Sharon Mwenda Date: Wed, 11 Oct 2023 11:06:05 +0300 Subject: [PATCH 2/4] fix:chnaghing variable name --- components/Books.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/Books.js b/components/Books.js index 0785b14..82120e4 100644 --- a/components/Books.js +++ b/components/Books.js @@ -333,8 +333,8 @@ class Books extends React.Component { console.log("IAIdentifier:", response.IAIdentifier); this.setState({ isValidIdentifier: false, - IATitle: response.IAIdentifier, - //IATitle: response.message, + //IATitle: response.IAIdentifier, + IATitle: response.IATitle, inputDisabled: true, }); } else { From b5379ccc6feda738d169249614df549505fd067c Mon Sep 17 00:00:00 2001 From: Sharon Mwenda Date: Wed, 11 Oct 2023 12:20:57 +0300 Subject: [PATCH 3/4] feat:added title to response --- components/Books.js | 9 +++++++-- server.js | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/components/Books.js b/components/Books.js index 82120e4..9df9414 100644 --- a/components/Books.js +++ b/components/Books.js @@ -210,6 +210,8 @@ class Books extends React.Component { }); let url = ""; + let Identifier = this.state.IAIdentifier; + console.log(Identifier); const isAlphanumericLess50 = /^(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9]{1,50}$/; switch (this.state.option) { case "gb": @@ -233,7 +235,8 @@ class Books extends React.Component { } else if (!isAlphanumericLess50.test(response.IAIdentifier)) { this.setState({ isValidIdentifier: false, - IATitle: response.IAIdentifier, + //IATitle: response.IAIdentifier, + IATitle: response.titleInIA, inputDisabled: true, }); console.log(response.IAIdentifier); @@ -316,6 +319,8 @@ class Books extends React.Component { }&categoryID=${categoryID}&userName=${userName}&IAtitle=${ this.state.IAIdentifier }`; + + console.log(url); fetch(url) .then((res) => res.json()) .then((response) => { @@ -334,7 +339,7 @@ class Books extends React.Component { this.setState({ isValidIdentifier: false, //IATitle: response.IAIdentifier, - IATitle: response.IATitle, + IATitle: response.titleInIA, inputDisabled: true, }); } else { diff --git a/server.js b/server.js index 8f0a799..c80e288 100644 --- a/server.js +++ b/server.js @@ -440,6 +440,7 @@ app } else { res.send({ error: false, + IAIdentifier: titleInIA, message: "You will be mailed with the details soon!", }); PDLProducer(bookid, titleInIA, categoryID, email, authUserName); From 2d627f7f07f16e8ad7a690a3df7d572c763bb6eb Mon Sep 17 00:00:00 2001 From: Sharon Mwenda Date: Wed, 11 Oct 2023 14:02:25 +0300 Subject: [PATCH 4/4] fix:alphanumeric bug --- components/Books.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/Books.js b/components/Books.js index 9df9414..a05c9c2 100644 --- a/components/Books.js +++ b/components/Books.js @@ -213,6 +213,7 @@ class Books extends React.Component { let Identifier = this.state.IAIdentifier; console.log(Identifier); const isAlphanumericLess50 = /^(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9]{1,50}$/; + const isAlphabetUniqueLess50 = /^[a-zA-Z0-9]{1,50}$/; switch (this.state.option) { case "gb": url = `${host}/check?bookid=${this.state.bookid}&option=${ @@ -334,7 +335,7 @@ class Books extends React.Component { IATitle: response.titleInIA, inputDisabled: true, }); - } else if (!isAlphanumericLess50.test(response.IAIdentifier)) { + } else if (!isAlphabetUniqueLess50.test(response.IAIdentifier)) { console.log("IAIdentifier:", response.IAIdentifier); this.setState({ isValidIdentifier: false,