Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api integration preview home page #380

Merged
merged 85 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
2ce0717
top bar header changes for editor screen
Nov 10, 2023
4308945
sitegenheader changes moved to step
Nov 10, 2023
2ae3769
sitegenheader changes moved to step
Nov 10, 2023
749584c
step editor drop down wip
Nov 12, 2023
8fb7dc0
changes for live preview wip
Nov 13, 2023
ff1f10c
screen design previws wip
Nov 14, 2023
8640b3c
design previews. respinsiveness remaining
Nov 14, 2023
ea4c1a1
added overlay for previews
Nov 14, 2023
d0436d0
minor fix
Nov 15, 2023
a6cfed2
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
Nov 22, 2023
9e48d8d
PRESS2-1262
Nov 22, 2023
1bacc06
Merge branch 'enhance/ai-onboarding' of github.com:newfold-labs/wp-mo…
Nov 23, 2023
64ef752
PRESS-1262 | fixed CSS
Nov 23, 2023
0d556b2
PRESS-1262 | note
Nov 24, 2023
323b0ea
PRESS-1262 | hide wp admin bar
Nov 24, 2023
07057cf
Merge branch 'Integrate-APIs-to-AI-Onboarding' of https://github.com/…
Nov 24, 2023
f2fa785
PRESS-1262
Nov 25, 2023
7a751ec
PRESS2-1262 | fixed changes
Nov 26, 2023
d9209c0
PRESS2-1262 | removed comments
Nov 27, 2023
43213d0
mobile changes
Nov 27, 2023
adb9303
Merge branch 'enhance/aio-design-previews' of github.com:newfold-labs…
Nov 27, 2023
492f947
have to change header background to dynamic
Nov 27, 2023
515fac7
have to change header background to dynamic
Nov 27, 2023
012ffd6
mobile responsiveness
Nov 28, 2023
238ae54
PRESS-1262 | updated controller
Nov 29, 2023
488e3d4
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
Nov 29, 2023
4c87a36
PRESS-1262 | fixed overlay button
Nov 29, 2023
a44e0a8
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
Nov 30, 2023
ae3168b
PRESS-1262 | comments removed
Nov 30, 2023
67251eb
Merge branch 'enhance/ai-onboarding' of github.com:newfold-labs/wp-mo…
Nov 30, 2023
ba544fb
PRESS-1237 | fixed version dropdown
Dec 1, 2023
1e0dca7
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
Dec 1, 2023
929434b
PRESS-1237 | fixed linting
Dec 1, 2023
1b64c3e
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
Dec 4, 2023
fbf2c97
PRESS2-1237 | reverted to textInput and fixed linting
Dec 4, 2023
472a6ce
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
Dec 4, 2023
ed469ec
PRESS2-1262 | added animation
Dec 5, 2023
e7a91c5
PRESS2-1237 | changed classname logic for editor header
Dec 5, 2023
0078d0d
Merge branch 'enhance/fix-dark-mode' of github.com:newfold-labs/wp-mo…
Dec 6, 2023
e947b40
Merge branch 'enhance/ai-onboarding' of github.com:newfold-labs/wp-mo…
Dec 6, 2023
3b7bd29
PRESS2-1262 | regenrating card
Dec 6, 2023
882ffe0
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
Dec 6, 2023
8263c55
PRESS2-1262 | add regenerating screen
Dec 6, 2023
1171b2d
PRESS2-1262 |
Dec 6, 2023
a497959
PRESS2-1262 | added to store
Dec 6, 2023
f84602b
PRESS2-1262 | added designs
Dec 6, 2023
18a2ada
Merge branch 'enhance/aio-preview' of https://github.com/newfold-labs…
Dec 7, 2023
efd85d0
PRESS2-1262 | added verion number in dropdown
Dec 7, 2023
2e6bf66
PRESS2-1262 | favorite toggle
Dec 7, 2023
4afc518
PRESS2-1262 | added on the sitegen object in store
Dec 7, 2023
f147fd9
PRESS2-1262 | integration home page
Dec 12, 2023
7c57bd3
PRESS-1262 | added home pages call
Dec 14, 2023
3163b56
PRESS2-1262 | created generating site loaders
Dec 15, 2023
39698d5
PRESS2-1465 | updated according to changes in option table
Dec 18, 2023
81c0168
PRESS2-1465
Dec 18, 2023
fa8ff4a
PRESS2-1465 | added regenerate changes
Dec 20, 2023
8d05642
PRESS2-1465 | regenerated api endpoint
Dec 20, 2023
be980c8
PRESS2-1465
Dec 21, 2023
4071e8f
Revert "PRESS2-1465 | regenerated api endpoint"
Dec 21, 2023
e49b0fe
PRESS2-1465
Dec 22, 2023
1008e48
PRESS2-1465 | regenerate functionality
Dec 28, 2023
f69ba4d
Merge branch 'enhance/ai-onboarding' into api-integration-preview-hom…
ajayadav09 Dec 29, 2023
c052920
updated preview
ajayadav09 Dec 29, 2023
7cc1db1
PRESS2-1465 | fixed linting issues
ajayadav09 Jan 2, 2024
91acf81
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
ajayadav09 Jan 2, 2024
500eacd
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
ajayadav09 Jan 3, 2024
bb4a753
Fixing PR comments | removed bg image
ajayadav09 Jan 3, 2024
9ab19d6
Press2-1465 | fixing PR comments
ajayadav09 Jan 4, 2024
976d931
Press2-1465 | updated get options from Option
ajayadav09 Jan 4, 2024
246bae9
PRESS2-1465 | changed favourite logic
ajayadav09 Jan 5, 2024
a390f20
PRESS2-1465 | fixed Option with get_option
ajayadav09 Jan 5, 2024
ae0be8b
PRESS2-1465 | fixed php linting
ajayadav09 Jan 8, 2024
5b00cf3
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
arunshenoy99 Jan 9, 2024
f62be25
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
arunshenoy99 Jan 9, 2024
3006c7e
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
arunshenoy99 Jan 9, 2024
a3ad4ef
PRESS2-1465 | added check
ajayadav09 Jan 10, 2024
953149e
PRESS2-1465 | handled error responses
ajayadav09 Jan 10, 2024
0d347b0
PRESS2-1465 | changed skeleton
ajayadav09 Jan 11, 2024
4b72509
Press2-1465 | updated preview
ajayadav09 Jan 11, 2024
8520596
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
ajayadav09 Jan 11, 2024
50ee515
Press2-1465 | hiding darkmode toggle from editor step
ajayadav09 Jan 11, 2024
0413114
Some Changes
officiallygod Jan 12, 2024
75e89b9
Update index.js
officiallygod Jan 12, 2024
09914b3
Update index.js
officiallygod Jan 12, 2024
00afc88
Delete sitegen-ai-animation.45cdf3b3.gif
ajayadav09 Jan 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 200 additions & 0 deletions includes/RestApi/SiteGenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace NewfoldLabs\WP\Module\Onboarding\RestApi;

use NewfoldLabs\WP\Module\Onboarding\Permissions;
use NewfoldLabs\WP\Module\AI\SiteGen\SiteGen;
use NewfoldLabs\WP\Module\Onboarding\Data\Services\SiteGenService;
use NewfoldLabs\WP\Module\Onboarding\Data\Options;

/**
* Class SiteGenController
Expand Down Expand Up @@ -49,6 +51,35 @@ public function register_routes() {
'args' => $this->sitegen_meta_args(),
)
);
\register_rest_route(
$this->namespace,
$this->rest_base . '/get-homepages',
array(
'methods' => \WP_REST_Server::CREATABLE,
'callback' => array( $this, 'get_homepages' ),
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ),
'args' => $this->get_homepages_args(),
)
);
\register_rest_route(
$this->namespace,
$this->rest_base . '/get-homepages-regenerate',
array(
'methods' => \WP_REST_Server::CREATABLE,
'callback' => array( $this, 'get_regenerated_homepages' ),
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ),
'args' => $this->get_homepages_regenerate_args(),
)
);
\register_rest_route(
$this->namespace,
$this->rest_base . '/favourites',
array(
'methods' => \WP_REST_Server::CREATABLE,
'callback' => array( $this, 'toggle_favourite_homepage' ),
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ),
)
);
}

/**
Expand All @@ -73,6 +104,53 @@ public function sitegen_meta_args() {
);
}

/**
* Gets the arguments for the 'get-homepages' endpoint.
*
* @return array The array of arguments.
*/
public function get_homepages_args() {
return array(
'site_description' => array(
'required' => true,
'validate_callback' => function ( $param ) {
return is_string( $param );
},
'sanitize_callback' => 'sanitize_text_field',
),
'regenerate' => array(
'required' => false,
),
// Add other parameters here as needed.
);
}

/**
* Gets the arguments for the 'get-homepages' endpoint.
*
* @return array The array of arguments.
*/
public function get_homepages_regenerate_args() {
return array(
'site_description' => array(
'required' => true,
'validate_callback' => function ( $param ) {
return is_string( $param );
},
'sanitize_callback' => 'sanitize_text_field',
),
'regenerate' => array(
'required' => false,
),
'slug' => array(
'required' => false,
),
'colorPalettes' => array(
'required' => false,
),
);
}

/**
* Gets all the valid Identifiers
*
Expand Down Expand Up @@ -105,4 +183,126 @@ public function generate_sitegen_meta( \WP_REST_Request $request ) {
// TODO Implement the main function and do computations if required.
return SiteGenService::instantiate_site_meta( $site_info, $identifier, $skip_cache );
}

/**
* Gets the preview homepages
*
* @param \WP_REST_Request $request parameter.
* @return array
*/
public function get_homepages( \WP_REST_Request $request ) {

$site_description = $request->get_param( 'site_description' );
$regenerate = $request->get_param( 'regenerate' );
$site_info = array( 'site_description' => $site_description );
// If the option exists and is not empty, return it.
$existing_homepages = get_option( Options::get_option_name( 'sitegen_homepages' ), array() );
if ( ! empty( $existing_homepages ) && ! $regenerate ) {
return new \WP_REST_Response( $existing_homepages, 200 );
}
$target_audience = SiteGenService::instantiate_site_meta( $site_info, 'target_audience' );
$content_style = SiteGenService::instantiate_site_meta( $site_info, 'content_tones' );

if ( ! $target_audience || is_wp_error( $target_audience ) ) {
return new \WP_Error(
'nfd_onboarding_error',
__( 'Required data is missing.', 'wp-module-onboarding' ),
array( 'status' => 400 )
);
}
if ( ! $content_style || is_wp_error( $content_style ) ) {
return new \WP_Error(
'nfd_onboarding_error',
__( 'Required data is missing.', 'wp-module-onboarding' ),
array( 'status' => 400 )
);
}

$processed_home_pages = SiteGenService::generate_homepages(
$site_description,
$content_style,
$target_audience,
$regenerate
);

if ( is_wp_error( $processed_home_pages ) ) {
return $processed_home_pages;
}

return new \WP_REST_Response( $processed_home_pages, 200 );
}

/**
* Gets the regenerated preview homepages
*
* @param \WP_REST_Request $request parameter.
* @return array
*/
public function get_regenerated_homepages( \WP_REST_Request $request ) {
$site_description = $request->get_param( 'site_description' );
$regenerate_slug = $request->get_param( 'slug' );
$regenerate_color_palattes = $request->get_param( 'colorPalettes' );
$is_favourite = $request->get_param( 'isFavourited' );
$site_info = array( 'site_description' => $site_description );
$target_audience = SiteGenService::instantiate_site_meta( $site_info, 'target_audience' );
$content_style = SiteGenService::instantiate_site_meta( $site_info, 'content_tones' );

if ( ! $target_audience || is_wp_error( $target_audience ) ) {
return new \WP_Error(
'nfd_onboarding_error',
__( 'Required data is missing.', 'wp-module-onboarding' ),
array( 'status' => 400 )
);
}

if ( ! $content_style || is_wp_error( $content_style ) ) {
return new \WP_Error(
'nfd_onboarding_error',
__( 'Required data is missing.', 'wp-module-onboarding' ),
array( 'status' => 400 )
);
}

if ( $is_favourite ) {
$result = SiteGenService::handle_favorite_regeneration( $regenerate_slug, $regenerate_color_palattes );
} else {
$result = SiteGenService::handle_regular_regeneration( $site_description, $content_style, $target_audience );
}

if ( null === $result ) {
return new \WP_Error(
'nfd_onboarding_error',
__( 'Error at Regenerating home pages.', 'wp-module-onboarding' ),
array(
'status' => 400,
)
);
}

return new \WP_REST_Response( $result, 200 );
}

/**
* Updates favourite status
*
* @param \WP_REST_Request $request parameter.
* @return array
*/
public function toggle_favourite_homepage( \WP_REST_Request $request ) {
$slug = $request->get_param( 'slug' );

$response = SiteGenService::toggle_favourite_homepage( $slug );

if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
return new \WP_Error(
'nfd_onboarding_error',
__( 'Error at updating Favourite status', 'wp-module-onboarding' ),
array(
'status' => 404,
)
);
}
return new \WP_REST_Response( $response, 200 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

&--dark {
background-color: var(--nfd-onboarding-navigation-back-background);
width: 74px;
height: 36px;
color: var(--nfd-onboarding-primary);
border-radius: 8px;
padding: 0, 13px, 0 13px;

&:hover {
background-color: #fff;
color: #272d30;
}
}
}
16 changes: 9 additions & 7 deletions src/OnboardingSPA/components/Button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
* Common Button Component
* Different variants can be added later based on our requirements
*
* @returns Button
* @return Button
*/

const Button = ({ text, handleClick, disabled, className }) => {
const Button = ( { children, onClick, disabled, className } ) => {
const handleBtnClick = () => {
handleClick();
if ( onClick ) {
onClick();
}
};

return (
<button
type="button"
className={`${className} nfd-card-button`}
onClick={handleBtnClick}
disabled={disabled}
className={ `${ className } nfd-card-button` }
onClick={ handleBtnClick }
disabled={ disabled }
>
{text}
{ children }
</button>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ import {
FOOTER_END,
} from '../../../../../constants';
import NextButtonSiteGen from '../../../Button/NextButtonSiteGen';
import { stepSiteGenEditor } from '../../.././../steps/SiteGen/Editor/step';

const SiteGenFooter = () => {
const isLargeViewport = useViewportMatch( 'small' );
const { footerNavEnabled } = useSelect( ( select ) => {
const { footerNavEnabled, currentStep } = useSelect( ( select ) => {
return {
footerNavEnabled:
select( nfdOnboardingStore ).getFooterNavEnabled(),
currentStep: select( nfdOnboardingStore ).getCurrentStep(),
};
} );

const isEditorStep = currentStep === stepSiteGenEditor;
return (
<>
<Fill name={ `${ FOOTER_SITEGEN }/${ FOOTER_START }` }>
<ToggleDarkMode />
{ ! isEditorStep && <ToggleDarkMode /> }
</Fill>
{ ! isLargeViewport && (
<Fill name={ `${ FOOTER_SITEGEN }/${ FOOTER_END }` }>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const SiteGenHeader = () => {
path: currentStep?.path,
} );
const progress = ( currentStepIndex / allSteps.length ) * 100;

return (
<>
<Fill name={ `${ HEADER_SITEGEN }/${ HEADER_TOP }` }>
Expand All @@ -48,10 +47,14 @@ const SiteGenHeader = () => {
) }
</>
</Fill>
<Fill name={ `${ HEADER_SITEGEN }/${ HEADER_START }` }>
<>{ isHeaderNavigationEnabled && <StepNavigation /> }</>
</Fill>
{ currentStep?.header && <currentStep.header /> }

{ currentStep?.header?.component
? isHeaderNavigationEnabled && <currentStep.header.component />
: isHeaderNavigationEnabled && (
<Fill name={ `${ HEADER_SITEGEN }/${ HEADER_START }` }>
<StepNavigation />
</Fill>
) }
</>
);
};
Expand Down
4 changes: 2 additions & 2 deletions src/OnboardingSPA/components/Header/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Slot } from '@wordpress/components';
import { Fragment, Suspense } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import classNames from 'classnames';

import { store as nfdOnboardingStore } from '../../store';
import {
Expand All @@ -9,19 +10,18 @@ import {
HEADER_START,
HEADER_TOP,
} from '../../../constants';
import classNames from 'classnames';
import { stepSiteGenEditor } from '../../steps/SiteGen/Editor/step';
import { SITEGEN_FLOW } from '../../data/flows/constants';

const Header = () => {
const { headers, headerActiveView, isHeaderEnabled, currentStep } =
useSelect( ( select ) => {
return {
currentStep: select( nfdOnboardingStore ).getCurrentStep(),
Comment on lines 17 to +20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can keep it in the same order i.e. var names and functions.

headers: select( nfdOnboardingStore ).getHeaders(),
headerActiveView:
select( nfdOnboardingStore ).getHeaderActiveView(),
isHeaderEnabled: select( nfdOnboardingStore ).isHeaderEnabled(),
currentStep: select( nfdOnboardingStore ).getCurrentStep(),
};
} );

Expand Down
Loading