diff --git a/includes/RestApi/RestApi.php b/includes/RestApi/RestApi.php index 8c2fba99b..e3bfb7dd3 100644 --- a/includes/RestApi/RestApi.php +++ b/includes/RestApi/RestApi.php @@ -29,6 +29,7 @@ final class RestApi { 'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeFontsController', 'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeColorsController', 'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\SiteClassificationController', + 'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\SiteGenController', ); /** diff --git a/includes/RestApi/SiteGenController.php b/includes/RestApi/SiteGenController.php new file mode 100644 index 000000000..f83eed0b2 --- /dev/null +++ b/includes/RestApi/SiteGenController.php @@ -0,0 +1,109 @@ +namespace, + $this->rest_base . '/get-identifiers', + array( + 'methods' => \WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_valid_identifiers' ), + 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), + ) + ); + \register_rest_route( + $this->namespace, + $this->rest_base . '/generate', + array( + 'methods' => \WP_REST_Server::CREATABLE, + 'callback' => array( $this, 'generate_sitegen_meta' ), + 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), + 'args' => $this->sitegen_meta_args(), + ) + ); + } + + /** + * Required Args for Generating Site Gen Meta. + * + * @return array + */ + public function sitegen_meta_args() { + return array( + 'site_info' => array( + 'required' => true, + 'type' => 'object', + ), + 'identifier' => array( + 'required' => true, + 'type' => 'string', + ), + 'skip_cache' => array( + 'required' => false, + 'type' => 'boolean', + ), + ); + } + + /** + * Gets all the valid Identifiers + * + * @return array + */ + public function get_valid_identifiers() { + return array_keys( array_filter( SiteGenService::get_identifiers() ) ); + } + + /** + * Generate Sitegen meta data. + * + * @param \WP_REST_Request $request Request model. + * + * @return array|WP_Error + */ + public function generate_sitegen_meta( \WP_REST_Request $request ) { + + $site_info = $request->get_param( 'site_info' ); + $identifier = $request->get_param( 'identifier' ); + $skip_cache = $request->get_param( 'skip_cache' ); + + if ( SiteGenService::is_enabled() ) { + // TODO Implement the main function and do computations if required. + return SiteGenService::instantiate_site_meta( $site_info, $identifier, $skip_cache ); + } + + return new \WP_Error( + 'sitegen-error', + 'SiteGen is Disabled.', + array( 'status' => 404 ) + ); + } +} diff --git a/src/OnboardingSPA/components/Button/NextButtonSiteGen/index.js b/src/OnboardingSPA/components/Button/NextButtonSiteGen/index.js index 145f392ea..1bfbe9627 100644 --- a/src/OnboardingSPA/components/Button/NextButtonSiteGen/index.js +++ b/src/OnboardingSPA/components/Button/NextButtonSiteGen/index.js @@ -5,7 +5,12 @@ import { Button } from '@wordpress/components'; import { Icon, chevronRight } from '@wordpress/icons'; import { store as nfdOnboardingStore } from '../../../store'; -const NextButtonSiteGen = ( { text, className, callback = null } ) => { +const NextButtonSiteGen = ( { + text, + className, + callback = null, + disabled = false, +} ) => { const navigate = useNavigate(); const { nextStep } = useSelect( ( select ) => { return { @@ -16,9 +21,13 @@ const NextButtonSiteGen = ( { text, className, callback = null } ) => {