Skip to content

Commit

Permalink
Merge pull request #324 from newfold-labs/PRESS-2-1194-Add-coming-soo…
Browse files Browse the repository at this point in the history
…n-to-Site-Features

Add Coming Soon to Site Features
  • Loading branch information
officiallygod authored Oct 6, 2023
2 parents cdbd7f7 + 8e67e91 commit 85e43fb
Show file tree
Hide file tree
Showing 16 changed files with 213 additions and 24 deletions.
43 changes: 43 additions & 0 deletions includes/RestApi/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,49 @@ public function register_routes() {
),
)
);

\register_rest_route(
$this->namespace,
$this->rest_base . '/coming-soon',
array(
array(
'methods' => \WP_REST_Server::CREATABLE,
'callback' => array( $this, 'set_coming_soon' ),
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ),
'args' => $this->set_coming_soon_params(),
),
)
);
}

/**
* Set query params for coming soon route.
*
* @return array
*/
public function set_coming_soon_params() {
return array(
'comingSoon' => array(
'type' => 'boolean',
'required' => true,
),
);
}
/**
* Endpoint to set Coming Soon for a website.
*
* @param \WP_REST_Request $request Request model.
*
* @return \WP_REST_Response|\WP_Error
*/
public function set_coming_soon( \WP_REST_Request $request ) {

$new_value = ( $request->get_param( 'comingSoon' ) ) ? 'true' : 'false';
update_option( 'nfd_coming_soon', $new_value );
return new \WP_REST_Response(
array(),
200
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const CheckboxItem = ( {
callback,
tabIndex = 0,
isSelectedDefault,
fullWidth = false,
className = 'checkbox-item',
} ) => {
const [ showDescription, setShowDescription ] = useState( false );
Expand All @@ -44,7 +45,9 @@ const CheckboxItem = ( {
<div
className={ `${ className } ${
isSelected && `${ className }--selected`
} ${ showDescription && `${ className }--shown` }` }
} ${ fullWidth && `${ className }--full-width` } ${
showDescription && `${ className }--shown`
}` }
>
<div className={ `${ className }-container` }>
<CheckboxControl
Expand Down Expand Up @@ -117,7 +120,13 @@ const CheckboxItem = ( {
className={ ` ${ className }__dropdown ` }
type={ 'dropdown' }
>
<div className={ `${ className }__desc` }>{ desc }</div>
<div
className={ `${ className }__desc ${
fullWidth && `${ className }__desc--full-width`
}` }
>
{ desc }
</div>
</Animate>
) }
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
width: clamp(15rem, 25vw, 35rem);
box-shadow: 0 2px 8px 2px rgba(204, 204, 204, 0.175295);

&--full-width {
width: clamp(15rem, 53.5vw, 74rem);

@media (max-width: #{ ($break-medium) }) {
width: clamp(15rem, 25vw, 35rem);
}
}

&-container {
display: flex;
align-items: center;
Expand Down Expand Up @@ -125,5 +133,13 @@
border-right: 1px solid rgba(var(--nfd-onboarding-highlighted--rgb), 0.1);
border-bottom: 1px solid rgba(var(--nfd-onboarding-highlighted--rgb), 0.1);
box-shadow: 0 11px 8px -3px rgba(var(--nfd-onboarding-highlighted--rgb), 0.37);

&--full-width {
width: clamp(15rem, 53.5vw, 74rem);

@media (max-width: #{ ($break-medium) }) {
width: clamp(15rem, 25vw, 35rem);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
.checkbox-list {
display: flex;
justify-content: center;
align-items: flex-start;
display: flex;
justify-content: center;
align-items: flex-start;

@media (max-width: #{ ($break-xlarge) }) {
flex-direction: column;
}
@media (max-width: #{ ($break-medium) }) {
flex-direction: column;
justify-content: center;
align-items: center;
}

&-col {
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
}
}
&-col {
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
}
}
27 changes: 27 additions & 0 deletions src/OnboardingSPA/components/ComingSoon/contents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { __, sprintf } from '@wordpress/i18n';

import { translations } from '../../utils/locales/translations';

const getContents = () => {
return {
title: __( 'Coming Soon', 'wp-module-onboarding' ),
subtitle: sprintf(
/* translators: %s: site or store */
__(
'Keep your %s private until you click launch',
'wp-module-onboarding'
),
translations( 'site' )
),
desc: sprintf(
/* translators: %s: site or store */
__(
"We'll show a placeholder page to logged-out visitors while you build your %s.",
'wp-module-onboarding'
),
translations( 'site' )
),
};
};

export default getContents;
40 changes: 40 additions & 0 deletions src/OnboardingSPA/components/ComingSoon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useSelect, useDispatch } from '@wordpress/data';

import getContents from './contents';
import { CheckboxItem } from '../CheckboxTemplate';
import { store as nfdOnboardingStore } from '../../store';

const ComingSoon = () => {
const content = getContents();

const { currentData } = useSelect( ( select ) => {
return {
currentData:
select( nfdOnboardingStore ).getCurrentOnboardingData(),
};
}, [] );

const { setCurrentOnboardingData } = useDispatch( nfdOnboardingStore );

async function handleComingSoon( name, selection ) {
currentData.data.comingSoon = selection;
setCurrentOnboardingData( currentData );
}

return (
<div className="coming_soon__wrapper">
<CheckboxItem
name="coming_soon"
title={ content.title }
subtitle={ content.subtitle }
icon={ '--site-features-comingsoon' }
desc={ content.desc }
callback={ handleComingSoon }
fullWidth={ true }
isSelectedDefault={ currentData?.data?.comingSoon }
/>
</div>
);
};

export default ComingSoon;
8 changes: 8 additions & 0 deletions src/OnboardingSPA/components/ComingSoon/stylesheet.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.coming_soon {

&__wrapper {
width: 100%;
display: flex;
justify-content: center;
}
}
2 changes: 2 additions & 0 deletions src/OnboardingSPA/components/ExitToWordPress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
CATEGORY,
} from '../../utils/analytics/hiive/constants';
import { activateInitialPlugins } from '../../utils/api/plugins';
import { setComingSoon } from '../../utils/api/comingSoon';

/**
* Self-contained button and confirmation modal for exiting Onboarding page.
Expand Down Expand Up @@ -101,6 +102,7 @@ const ExitToWordPress = ( {
}
}
setFlow( currentData );
setComingSoon( currentData?.data?.comingSoon );
}
activateInitialPlugins();
trackOnboardingEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { pluginDashboardPage } from '../../../../../constants';
import { setFlow } from '../../../../utils/api/flow';
import { ACTION_ONBOARDING_COMPLETE } from '../../../../utils/analytics/hiive/constants';
import { setComingSoon } from '../../../../utils/api/comingSoon';

const ChapterInterstitialLoader = () => {
const [ countdown, setCountdown ] = useState( 15 );
Expand All @@ -29,6 +30,7 @@ const ChapterInterstitialLoader = () => {
if ( currentData ) {
currentData.isComplete = new Date().getTime();
setFlow( currentData );
setComingSoon( currentData?.data?.comingSoon );
}

activateInitialPlugins();
Expand Down
3 changes: 3 additions & 0 deletions src/OnboardingSPA/static/icons/site-features/comingsoon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 17 additions & 8 deletions src/OnboardingSPA/steps/Complete/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { StepLoader } from '../../components/Loaders';
import { StepErrorState } from '../../components/ErrorState';
import { THEME_STATUS_INIT } from '../../../constants';
import { DesignStateHandler } from '../../components/StateHandlers';
import { setComingSoon } from '../../utils/api/comingSoon';

const StepComplete = () => {
const {
Expand All @@ -22,18 +23,26 @@ const StepComplete = () => {
const navigate = useNavigate();
const [ isError, setIsError ] = useState( false );

const { nextStep, brandName, isQueueEmpty } = useSelect( ( select ) => {
return {
nextStep: select( nfdOnboardingStore ).getNextStep(),
brandName: select( nfdOnboardingStore ).getNewfoldBrandName(),
isQueueEmpty: select( nfdOnboardingStore ).isQueueEmpty(),
};
}, [] );
const { nextStep, brandName, isQueueEmpty, currentData } = useSelect(
( select ) => {
return {
nextStep: select( nfdOnboardingStore ).getNextStep(),
brandName: select( nfdOnboardingStore ).getNewfoldBrandName(),
isQueueEmpty: select( nfdOnboardingStore ).isQueueEmpty(),
currentData:
select( nfdOnboardingStore ).getCurrentOnboardingData(),
};
},
[]
);

const contents = getContents( brandName );

const checkFlowComplete = async () => {
await Promise.all( [ completeFlowRequest() ] ).then( ( values ) =>
await Promise.all( [
completeFlowRequest(),
setComingSoon( currentData?.data?.comingSoon ),
] ).then( ( values ) =>
values.forEach( ( value ) => {
// If any Request returns False then Show Error
if ( ! value ) {
Expand Down
4 changes: 3 additions & 1 deletion src/OnboardingSPA/steps/SiteFeatures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import HeadingWithSubHeading from '../../components/HeadingWithSubHeading';
import CheckboxList from '../../components/CheckboxTemplate/CheckboxList';
import { CheckboxListSkeleton } from '../../components/CheckboxTemplate';
import getContents from './contents';
import ComingSoon from '../../components/ComingSoon';

const StepSiteFeatures = () => {
const isLargeViewport = useViewportMatch( 'medium' );
Expand Down Expand Up @@ -91,7 +92,7 @@ const StepSiteFeatures = () => {

return (
<CommonLayout>
<div style={ { margin: '100px' } }>
<div className="site-features__heading">
<HeadingWithSubHeading
title={ content.heading }
subtitle={ content.subheading }
Expand All @@ -112,6 +113,7 @@ const StepSiteFeatures = () => {
customItemsList={ customPluginsList }
/>
) }
{ customPluginsList && <ComingSoon /> }
</CommonLayout>
);
};
Expand Down
7 changes: 7 additions & 0 deletions src/OnboardingSPA/steps/SiteFeatures/stylesheet.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.site-features__heading {
margin: 100px;

@media (max-width: #{ ($break-medium) }) {
margin: 0;
}
}
1 change: 1 addition & 0 deletions src/OnboardingSPA/styles/_icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ body {
--site-features-security: url(../static/icons/site-features/security.svg);
--site-features-share: url(../static/icons/site-features/share.svg);
--site-features-wishlist: url(../static/icons/site-features/wishlist.svg);
--site-features-comingsoon: url(../static/icons/site-features/comingsoon.svg);
}
2 changes: 2 additions & 0 deletions src/OnboardingSPA/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
@import "../components/NewfoldInterfaceSkeleton/style";
@import "../components/Loaders/Chapter/Interstitial/stylesheet";
@import "../components/Grid/stylesheet";
@import "../components/ComingSoon/stylesheet";

// CSS for Pages
@import "../steps/BasicInfo/stylesheet";
Expand All @@ -55,6 +56,7 @@
@import "../steps/SitePages/stylesheet";
@import "../steps/DesignFonts/stylesheet";
@import "../steps/DesignHeaderMenu/stylesheet";
@import "../steps/SiteFeatures/stylesheet";

.nfd-onboarding-container {
display: flex;
Expand Down
16 changes: 16 additions & 0 deletions src/OnboardingSPA/utils/api/comingSoon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { onboardingRestURL } from './common';
import { resolve } from './resolve';

import apiFetch from '@wordpress/api-fetch';

export async function setComingSoon( comingSoon ) {
return await resolve(
apiFetch( {
url: onboardingRestURL( 'settings/coming-soon' ),
method: 'POST',
data: {
comingSoon,
},
} ).then()
);
}

0 comments on commit 85e43fb

Please sign in to comment.