0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-08 07:32:40 +00:00

Popup error when gDrive credentials are expired on both /edit and /new

This commit is contained in:
Trevor Buckner
2021-08-11 15:36:57 -04:00
parent a48c74b2e7
commit 0075b0836a
5 changed files with 188 additions and 16 deletions

View File

@@ -322,7 +322,9 @@ const EditPage = createClass({
let errMsg = ''; let errMsg = '';
try { try {
errMsg += `${this.state.errors.toString()}\n\n`; errMsg += `${this.state.errors.toString()}\n\n`;
errMsg += `\`\`\`\n${JSON.stringify(this.state.errors.response.error, null, ' ')}\n\`\`\``; errMsg += `\`\`\`\n${this.state.errors.stack}\n`;
errMsg += `${JSON.stringify(this.state.errors.response.error, null, ' ')}\n\`\`\``;
console.log(errMsg);
} catch (e){} } catch (e){}
if(this.state.errors.status == '401'){ if(this.state.errors.status == '401'){
@@ -344,6 +346,27 @@ const EditPage = createClass({
</Nav.item>; </Nav.item>;
} }
if(this.state.errors.status == '403' && this.state.errors.response.body.errors[0].reason == 'insufficientPermissions'){
return <Nav.item className='save error' icon='fas fa-exclamation-triangle'>
Oops!
<div className='errorContainer' onClick={this.clearErrors}>
Looks like your Google credentials have
expired! Visit the log in page to sign out
and sign back in with Google
to save this to Google Drive!
<a target='_blank' rel='noopener noreferrer'
href={`https://www.naturalcrit.com/login?redirect=${this.state.url}`}>
<div className='confirm'>
Sign In
</div>
</a>
<div className='deny'>
Not Now
</div>
</div>
</Nav.item>;
}
return <Nav.item className='save error' icon='fas fa-exclamation-triangle'> return <Nav.item className='save error' icon='fas fa-exclamation-triangle'>
Oops! Oops!
<div className='errorContainer'> <div className='errorContainer'>

View File

@@ -61,7 +61,7 @@ const NewPage = createClass({
isSaving : false, isSaving : false,
saveGoogle : (global.account && global.account.googleId ? true : false), saveGoogle : (global.account && global.account.googleId ? true : false),
errors : [], errors : null,
htmlErrors : Markdown.validate(this.props.brew.text) htmlErrors : Markdown.validate(this.props.brew.text)
}; };
}, },
@@ -138,6 +138,14 @@ const NewPage = createClass({
})); }));
}, },
clearErrors : function(){
this.setState({
errors : null,
isSaving : false
});
},
save : async function(){ save : async function(){
this.setState({ this.setState({
isSaving : true isSaving : true
@@ -161,7 +169,7 @@ const NewPage = createClass({
console.log(err.status === 401 console.log(err.status === 401
? 'Not signed in!' ? 'Not signed in!'
: 'Error Creating New Google Brew!'); : 'Error Creating New Google Brew!');
this.setState({ isSaving: false }); this.setState({ isSaving: false, errors: err });
return; return;
}); });
@@ -191,12 +199,73 @@ const NewPage = createClass({
}, },
renderSaveButton : function(){ renderSaveButton : function(){
if(this.state.errors){
let errMsg = '';
try {
errMsg += `${this.state.errors.toString()}\n\n`;
errMsg += `\`\`\`\n${this.state.errors.stack}\n`;
errMsg += `${JSON.stringify(this.state.errors.response.error, null, ' ')}\n\`\`\``;
console.log(errMsg);
} catch (e){}
if(this.state.errors.status == '401'){
return <Nav.item className='save error' icon='fas fa-exclamation-triangle'>
Oops!
<div className='errorContainer' onClick={this.clearErrors}>
You must be signed in to a Google account
to save this to<br />Google Drive!<br />
<a target='_blank' rel='noopener noreferrer'
href={`https://www.naturalcrit.com/login?redirect=${this.state.url}`}>
<div className='confirm'>
Sign In
</div>
</a>
<div className='deny'>
Not Now
</div>
</div>
</Nav.item>;
}
if(this.state.errors.status == '403' && this.state.errors.response.body.errors[0].reason == 'insufficientPermissions'){
return <Nav.item className='save error' icon='fas fa-exclamation-triangle'>
Oops!
<div className='errorContainer' onClick={this.clearErrors}>
Looks like your Google credentials have
expired! Visit the log in page to sign out
and sign back in with Google
to save this to Google Drive!
<a target='_blank' rel='noopener noreferrer'
href={`https://www.naturalcrit.com/login?redirect=${this.state.url}`}>
<div className='confirm'>
Sign In
</div>
</a>
<div className='deny'>
Not Now
</div>
</div>
</Nav.item>;
}
return <Nav.item className='save error' icon='fas fa-exclamation-triangle'>
Oops!
<div className='errorContainer'>
Looks like there was a problem saving. <br />
Report the issue <a target='_blank' rel='noopener noreferrer'
href={`https://github.com/naturalcrit/homebrewery/issues/new?body=${encodeURIComponent(errMsg)}`}>
here
</a>.
</div>
</Nav.item>;
}
if(this.state.isSaving){ if(this.state.isSaving){
return <Nav.item icon='fas fa-spinner fa-spin' className='saveButton'> return <Nav.item icon='fas fa-spinner fa-spin' className='save'>
save... save...
</Nav.item>; </Nav.item>;
} else { } else {
return <Nav.item icon='fas fa-save' className='saveButton' onClick={this.save}> return <Nav.item icon='fas fa-save' className='save' onClick={this.save}>
save save
</Nav.item>; </Nav.item>;
} }

View File

@@ -1,10 +1,82 @@
.newPage{ .newPage{
.navItem.save{
.saveButton{
background-color: @orange; background-color: @orange;
&:hover{ &:hover{
background-color: @green; background-color: @green;
} }
&.error{
position : relative;
background-color : @red;
}
} }
.errorContainer{
} animation-name: glideDown;
animation-duration: 0.4s;
position : absolute;
top : 100%;
left : 50%;
z-index : 100000;
width : 140px;
padding : 3px;
color : white;
background-color : #333;
border : 3px solid #444;
border-radius : 5px;
transform : translate(-50% + 3px, 10px);
text-align : center;
font-size : 10px;
font-weight : 800;
text-transform : uppercase;
a{
color : @teal;
}
&:before {
content: "";
width: 0px;
height: 0px;
position: absolute;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 10px solid transparent;
border-bottom: 10px solid #444;
left: 53px;
top: -23px;
}
&:after {
content: "";
width: 0px;
height: 0px;
position: absolute;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 10px solid transparent;
border-bottom: 10px solid #333;
left: 53px;
top: -19px;
}
.deny {
width : 48%;
margin : 1px;
padding : 5px;
background-color : #333;
display : inline-block;
border-left : 1px solid #666;
.animate(background-color);
&:hover{
background-color : red;
}
}
.confirm {
width : 48%;
margin : 1px;
padding : 5px;
background-color : #333;
display : inline-block;
color : white;
.animate(background-color);
&:hover{
background-color : teal;
}
}
}
}

View File

@@ -168,6 +168,7 @@ GoogleActions = {
.catch((err)=>{ .catch((err)=>{
console.log('Error saving to google'); console.log('Error saving to google');
console.error(err); console.error(err);
throw (err);
//return res.status(500).send('Error while saving'); //return res.status(500).send('Error while saving');
}); });
} }
@@ -203,8 +204,9 @@ GoogleActions = {
media : media media : media
}) })
.catch((err)=>{ .catch((err)=>{
console.log('Error while creating new Google brew');
console.error(err); console.error(err);
return res.status(500).send('Error while creating google brew'); throw (err);
}); });
if(!obj) return; if(!obj) return;

View File

@@ -141,9 +141,12 @@ const newGoogleBrew = async (req, res, next)=>{
req.body = brew; req.body = brew;
const newBrew = await GoogleActions.newGoogleBrew(oAuth2Client, brew); try {
const newBrew = await GoogleActions.newGoogleBrew(oAuth2Client, brew);
return res.status(200).send(newBrew); return res.status(200).send(newBrew);
} catch (err) {
return res.status(err.response.status).send(err);
}
}; };
const updateGoogleBrew = async (req, res, next)=>{ const updateGoogleBrew = async (req, res, next)=>{
@@ -154,9 +157,12 @@ const updateGoogleBrew = async (req, res, next)=>{
const brew = req.body; const brew = req.body;
brew.text = mergeBrewText(brew.text, brew.style); brew.text = mergeBrewText(brew.text, brew.style);
const updatedBrew = await GoogleActions.updateGoogleBrew(oAuth2Client, brew); try {
const updatedBrew = await GoogleActions.updateGoogleBrew(oAuth2Client, brew);
return res.status(200).send(updatedBrew); return res.status(200).send(updatedBrew);
} catch (err) {
return res.status(err.response.status).send(err);
}
}; };
router.post('/api', newBrew); router.post('/api', newBrew);