const React = require('react'); const moment = require('moment'); const UIPage = require('../basePages/uiPage/uiPage.jsx'); const NaturalCritIcon = require('naturalcrit/svg/naturalcrit.svg.jsx'); let SAVEKEY = ''; const AccountPage = (props)=>{ // destructure props and set state for save location const { accountDetails, brew } = props; const [saveLocation, setSaveLocation] = React.useState(''); // initialize save location from local storage based on user id React.useEffect(()=>{ if(!saveLocation && accountDetails.username) { SAVEKEY = `HOMEBREWERY-DEFAULT-SAVE-LOCATION-${accountDetails.username}`; // if no SAVEKEY in local storage, default save location to Google Drive if user has Google account. let saveLocation = window.localStorage.getItem(SAVEKEY); saveLocation = saveLocation ?? (accountDetails.googleId ? 'GOOGLE-DRIVE' : 'HOMEBREWERY'); setActiveSaveLocation(saveLocation); } }, []); const setActiveSaveLocation = (newSelection)=>{ if(saveLocation === newSelection) return; window.localStorage.setItem(SAVEKEY, newSelection); setSaveLocation(newSelection); }; // todo: should this be a set of radio buttons (well styled) since it's either/or choice? const renderSaveLocationButton = (name, key, shouldRender = true)=>{ if(!shouldRender) return null; return ( ); }; // render the entirety of the account page content const renderAccountPage = ()=>{ return ( <>

Account Information

Username: {accountDetails.username || 'No user currently logged in'}

Last Login: {moment(accountDetails.issued).format('dddd, MMMM Do YYYY, h:mm:ss a ZZ') || '-'}

Homebrewery Information

Brews on Homebrewery: {accountDetails.mongoCount}

Google Information

Linked to Google: {accountDetails.googleId ? 'YES' : 'NO'}

{accountDetails.googleId && (

Brews on Google Drive: {accountDetails.googleCount ?? ( <> Unable to retrieve files - follow these steps to renew your Google credentials. )}

)}

Default Save Location

{renderSaveLocationButton('Homebrewery', 'HOMEBREWERY')} {renderSaveLocationButton('Google Drive', 'GOOGLE-DRIVE', accountDetails.googleId)}
); }; // return the account page inside the base layout wrapper (with navbar etc). return ( {renderAccountPage()} ); }; module.exports = AccountPage;