Skip to content

Commit

Permalink
Add Error State Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
officiallygod committed Jul 1, 2024
1 parent 50ace2a commit aee8cb0
Showing 1 changed file with 79 additions and 77 deletions.
156 changes: 79 additions & 77 deletions src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ import {
ACTION_SITEGEN_LOGO_SKIPPED,
} from '../../../utils/analytics/hiive/constants';
import { SITEGEN_FLOW } from '../../../data/flows/constants';
import { SiteGenStateHandler } from '../../../components/StateHandlers';

const SiteGenSiteLogo = () => {
const [ siteLogo, setSiteLogo ] = useState();
const [siteLogo, setSiteLogo] = useState();

Check failure on line 33 in src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

A space is required after '['

Check failure on line 33 in src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

A space is required before ']'

const isLargeViewport = useViewportMatch( 'small' );
const isLargeViewport = useViewportMatch('small');

Check failure on line 35 in src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

There must be a space after this paren

Check failure on line 35 in src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

There must be a space before this paren

const { currentData } = useSelect( ( select ) => {
const { currentData } = useSelect((select) => {

Check failure on line 37 in src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

There must be a space after this paren

Check failure on line 37 in src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

There must be a space after this paren

Check failure on line 37 in src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

There must be a space before this paren
return {
currentData:
select( nfdOnboardingStore ).getCurrentOnboardingData(),
currentData: select(nfdOnboardingStore).getCurrentOnboardingData(),

Check failure on line 39 in src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

There must be a space after this paren

Check failure on line 39 in src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

There must be a space before this paren
};
} );
});

Check failure on line 41 in src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

There must be a space before this paren

const { getEditedEntityRecord } = useSelect( ( select ) => {
return select( coreStore );
}, [] );
const { getEditedEntityRecord } = useSelect((select) => {
return select(coreStore);
}, []);

const { editEntityRecord } = useDispatch( coreStore );
const { editEntityRecord } = useDispatch(coreStore);

const {
setIsFooterNavAllowed,
Expand All @@ -56,22 +56,22 @@ const SiteGenSiteLogo = () => {
setCurrentOnboardingData,
setIsHeaderNavigationEnabled,
updateSiteGenErrorStatus,
} = useDispatch( nfdOnboardingStore );

useEffect( () => {
setHideFooterNav( false );
setIsHeaderEnabled( true );
setSidebarActiveView( false );
setIsHeaderNavigationEnabled( true );
setHeaderActiveView( HEADER_SITEGEN );
setDrawerActiveView( false );
if ( currentData.sitegen.siteLogo?.id !== 0 ) {
setIsFooterNavAllowed( true );
return setSiteLogo( currentData.sitegen.siteLogo );
} = useDispatch(nfdOnboardingStore);

useEffect(() => {
setHideFooterNav(false);
setIsHeaderEnabled(true);
setSidebarActiveView(false);
setIsHeaderNavigationEnabled(true);
setHeaderActiveView(HEADER_SITEGEN);
setDrawerActiveView(false);
if (currentData.sitegen.siteLogo?.id !== 0) {
setIsFooterNavAllowed(true);
return setSiteLogo(currentData.sitegen.siteLogo);
}
setIsFooterNavAllowed( false );
getEditedEntityRecord( 'root', 'site' );
}, [] );
setIsFooterNavAllowed(false);
getEditedEntityRecord('root', 'site');
}, []);

Check warning on line 74 in src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'currentData.sitegen.siteLogo', 'getEditedEntityRecord', 'setDrawerActiveView', 'setHeaderActiveView', 'setHideFooterNav', 'setIsFooterNavAllowed', 'setIsHeaderEnabled', 'setIsHeaderNavigationEnabled', and 'setSidebarActiveView'. Either include them or remove the dependency array

const resetSiteLogo = () => {
const currentDataCopy = { ...currentData };
Expand All @@ -81,28 +81,28 @@ const SiteGenSiteLogo = () => {
fileName: '',
fileSize: 0,
};
setCurrentOnboardingData( currentDataCopy );
setSiteLogo( undefined );
setIsFooterNavAllowed( false );
setCurrentOnboardingData(currentDataCopy);
setSiteLogo(undefined);
setIsFooterNavAllowed(false);
trackOnboardingEvent(
new OnboardingEvent( ACTION_SITEGEN_LOGO_SKIPPED, undefined, {
new OnboardingEvent(ACTION_SITEGEN_LOGO_SKIPPED, undefined, {
source: SITEGEN_FLOW,
} )
})
);
};

const handleSiteLogo = ( siteLogoNew ) => {
const handleSiteLogo = (siteLogoNew) => {
const currentDataCopy = { ...currentData };
currentDataCopy.sitegen.siteLogo.id = siteLogoNew.id;
currentDataCopy.sitegen.siteLogo.url = siteLogoNew.url;
currentDataCopy.sitegen.siteLogo.fileName = siteLogoNew.fileName;
currentDataCopy.sitegen.siteLogo.fileSize = siteLogoNew.fileSize;
setCurrentOnboardingData( currentDataCopy );
setIsFooterNavAllowed( siteLogoNew.id !== 0 );
editEntityRecord( 'root', 'site', undefined, {
setCurrentOnboardingData(currentDataCopy);
setIsFooterNavAllowed(siteLogoNew.id !== 0);
editEntityRecord('root', 'site', undefined, {
site_logo: siteLogoNew.id,
} );
setSiteLogo( siteLogoNew );
});
setSiteLogo(siteLogoNew);
};

const handleFailure = () => {
Expand All @@ -115,55 +115,57 @@ const SiteGenSiteLogo = () => {
}
)
);
updateSiteGenErrorStatus( true );
updateSiteGenErrorStatus(true);
};

const content = getContents();

return (
<CommonLayout
isCentered
className="nfd-onboarding-step--site-gen__site-logo"
>
<div className="nfd-onboarding-step--site-gen__site-logo__container">
<AIHeading title={ content.heading } />
<ImageUploaderWithText
image={ siteLogo }
imageSetter={ handleSiteLogo }
onFailure={ handleFailure }
/>
<div className="nfd-onboarding-step--site-gen__site-logo__container__buttons">
<SkipButton
callback={ () => resetSiteLogo() }
className="nfd-onboarding-step--site-gen__site-logo__container__buttons__skip"
text={ content.buttons.skip }
<SiteGenStateHandler>
<CommonLayout
isCentered
className="nfd-onboarding-step--site-gen__site-logo"
>
<div className="nfd-onboarding-step--site-gen__site-logo__container">
<AIHeading title={content.heading} />
<ImageUploaderWithText
image={siteLogo}
imageSetter={handleSiteLogo}
onFailure={handleFailure}
/>
{ isLargeViewport && (
<NextButtonSiteGen
callback={ () => {
if ( siteLogo ) {
trackOnboardingEvent(
new OnboardingEvent(
ACTION_LOGO_ADDED,
undefined,
{
source: SITEGEN_FLOW,
}
)
);
}
} }
text={ content.buttons.next }
disabled={
siteLogo === undefined || siteLogo?.id === 0
? true
: false
}
<div className="nfd-onboarding-step--site-gen__site-logo__container__buttons">
<SkipButton
callback={() => resetSiteLogo()}
className="nfd-onboarding-step--site-gen__site-logo__container__buttons__skip"
text={content.buttons.skip}
/>
) }
{isLargeViewport && (
<NextButtonSiteGen
callback={() => {
if (siteLogo) {
trackOnboardingEvent(
new OnboardingEvent(
ACTION_LOGO_ADDED,
undefined,
{
source: SITEGEN_FLOW,
}
)
);
}
}}
text={content.buttons.next}
disabled={
siteLogo === undefined || siteLogo?.id === 0
? true
: false
}
/>
)}
</div>
</div>
</div>
</CommonLayout>
</CommonLayout>
</SiteGenStateHandler>
);
};

Expand Down

0 comments on commit aee8cb0

Please sign in to comment.