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

Adding simple customer promt screen #382

Merged
merged 31 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c27cfdc
initial commit
girish-lokapure Nov 30, 2023
89b0a61
ui changes
girish-lokapure Nov 30, 2023
64359df
Merge branch 'enhance/ai-onboarding' of github.com:newfold-labs/wp-mo…
girish-lokapure Nov 30, 2023
230ee7e
layout changes
girish-lokapure Dec 4, 2023
e59c86f
storing data in store and db
girish-lokapure Dec 5, 2023
f4f7bcc
code cleanup
girish-lokapure Dec 5, 2023
fc638dc
lint fixes
girish-lokapure Dec 5, 2023
04981f8
merged ai-onboarding
girish-lokapure Dec 6, 2023
616fe15
fixed lint issues
girish-lokapure Dec 6, 2023
2a33861
PRESS2-1913 | replaced filename casing
Dec 7, 2023
e5340c1
questionnaire from api
girish-lokapure Dec 12, 2023
bf45801
lint fixes
girish-lokapure Dec 12, 2023
a4fc45c
resetting build
girish-lokapure Dec 13, 2023
bd6a2cc
resetting build
girish-lokapure Dec 13, 2023
dbfc279
resetting build
girish-lokapure Dec 13, 2023
fc18656
PR changes
girish-lokapure Dec 18, 2023
1364820
lint fixes
girish-lokapure Dec 18, 2023
e77db69
Merge branch 'enhance/ai-onboarding' of github.com:newfold-labs/wp-mo…
girish-lokapure Dec 18, 2023
288e2a3
Update stylesheet.scss
girish-lokapure Dec 18, 2023
1780d4f
Update stylesheet.scss
girish-lokapure Dec 18, 2023
80b1ae3
New screen changes
girish-lokapure Dec 21, 2023
cfecccc
Update stylesheet.scss
girish-lokapure Dec 21, 2023
c170c26
Update stylesheet.scss
girish-lokapure Dec 27, 2023
0f0a804
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
arunshenoy99 Jan 9, 2024
fc44851
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
arunshenoy99 Jan 9, 2024
59c579d
PR changes
girish-lokapure Jan 9, 2024
a3b4d5b
Merge branch 'add/sitedetails/simple' of github.com:newfold-labs/wp-m…
girish-lokapure Jan 9, 2024
5fa6c96
Merge branch 'enhance/ai-onboarding' of github.com:newfold-labs/wp-mo…
girish-lokapure Jan 10, 2024
147a026
lint fixes
girish-lokapure Jan 10, 2024
d3044f5
Update stylesheet.scss
girish-lokapure Jan 10, 2024
863cabb
Merge branch 'enhance/ai-onboarding' of github.com:newfold-labs/wp-mo…
girish-lokapure Jan 15, 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
21 changes: 21 additions & 0 deletions includes/RestApi/SiteGenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use NewfoldLabs\WP\Module\AI\SiteGen\SiteGen;
use NewfoldLabs\WP\Module\Onboarding\Data\Services\SiteGenService;
use NewfoldLabs\WP\Module\Onboarding\Data\Options;
use NewfoldLabs\WP\Module\Onboarding\Data\SiteGen as SiteGenData;

/**
* Class SiteGenController
Expand Down Expand Up @@ -80,6 +81,15 @@ public function register_routes() {
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ),
)
);
\register_rest_route(
$this->namespace,
$this->rest_base . '/site-details-meta',
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( $this, 'get_site_details_meta' ),
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ),
)
);
}

/**
Expand Down Expand Up @@ -305,4 +315,15 @@ public function toggle_favourite_homepage( \WP_REST_Request $request ) {
}
return new \WP_REST_Response( $response, 200 );
}

/**
* Generate Sitegen Site Details meta data.
*
* @param \WP_REST_Request $request Request model.
*
* @return array|WP_Error
*/
public function get_site_details_meta( \WP_REST_Request $request ) {
return SiteGenData::get_site_details_questionnaire();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useRef, memo } from '@wordpress/element';

const TextAreaSiteGenDetails = ( {
labelText,
placeholder,
customerInput,
callback = null,
} ) => {
const textareaRef = useRef( null );

return (
<div>
<label htmlFor={ labelText }>{ labelText }</label>
<div className="nfd-sg-simple-input">
<textarea
type="text"
ref={ textareaRef }
placeholder={ placeholder }
value={ customerInput }
onChange={ ( e ) => {
if ( callback && typeof callback === 'function' ) {
callback( e );
}
} }
/>
</div>
</div>
);
};

export default memo( TextAreaSiteGenDetails );
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@


.nfd-sg-simple-input {
margin-top: 20px;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { memo } from '@wordpress/element';

const TextInputSiteGenDetails = ( {
labelText,
placeholder,
customerInput,
callback = null,
} ) => {
return (
<div>
<label htmlFor={ labelText }>{ labelText }</label>
<div className="nfd-sg-simple-input">
<input
type="text"
placeholder={ placeholder }
value={ customerInput }
onChange={ ( e ) => {
if ( callback && typeof callback === 'function' ) {
callback( e );
}
} }
/>
</div>
</div>
);
};

export default memo( TextInputSiteGenDetails );
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@


.nfd-sg-simple-input {
margin-top: 20px;

}
5 changes: 5 additions & 0 deletions src/OnboardingSPA/steps/SiteGen/SiteDetails/contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const getContents = () => {
),
inputHint: __( 'The more detail the better', 'wp-module-onboarding' ),
buttonText: __( 'Next', 'wp-module-onboarding' ),
walkThroughText: __(
'Not sure what to say? We can walk you through it.',
'wp-module-onboarding'
),
walkThroughlink: __( 'click here', 'wp-module-onboarding' ),
};
};

Expand Down
98 changes: 73 additions & 25 deletions src/OnboardingSPA/steps/SiteGen/SiteDetails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
import TextInputSiteGen from '../../../components/TextInput/TextInputSiteGen';
import NextButtonSiteGen from '../../../components/Button/NextButtonSiteGen';

import SiteGenSiteDetailsWalkthrough from '../SiteDetails/walkthrough';
import { getSiteDetailsQuestionare } from '../../../utils/api/siteGen';

const SiteGenSiteDetails = () => {
const content = getContents();
const isLargeViewport = useViewportMatch( 'small' );
const [ customerInput, setCustomerInput ] = useState();
const [ isValidInput, setIsValidInput ] = useState( false );

const [ isWalkthrough, setIsWalkthrough ] = useState( false );
const [ siteDetailsmeta, setSiteDetailsmeta ] = useState();
const { currentData } = useSelect( ( select ) => {
return {
currentData:
Expand All @@ -38,48 +42,92 @@
setSidebarActiveView( false );
setHeaderActiveView( HEADER_SITEGEN );
setDrawerActiveView( false );

setFooterNavEnabled( false );
if ( currentData.sitegen.siteDetails?.prompt !== '' ) {
setIsValidInput( true );
setFooterNavEnabled( true );
setFooterNavEnabled( isValidInput );
return setCustomerInput( currentData.sitegen.siteDetails.prompt );
}
setFooterNavEnabled( false );
}, [] );

Check warning on line 51 in src/OnboardingSPA/steps/SiteGen/SiteDetails/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'currentData.sitegen.siteDetails.prompt', 'isValidInput', 'setDrawerActiveView', 'setFooterNavEnabled', 'setHeaderActiveView', 'setIsHeaderEnabled', and 'setSidebarActiveView'. Either include them or remove the dependency array

useEffect( () => {
if ( customerInput?.trim() === '' ) {
setFooterNavEnabled( false );
} else {
if (
currentData.sitegen.siteDetails.prompt !== undefined &&
customerInput !== undefined &&
customerInput !== currentData.sitegen.siteDetails.prompt
) {
setFooterNavEnabled( isValidInput );
currentData.sitegen.siteDetails.prompt = customerInput?.trim();
currentData.sitegen.siteDetails.mode = 'simple';
setCurrentOnboardingData( currentData );
} else {
setFooterNavEnabled( false );
}
}, [ customerInput ] );

Check warning on line 66 in src/OnboardingSPA/steps/SiteGen/SiteDetails/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'currentData', 'isValidInput', 'setCurrentOnboardingData', and 'setFooterNavEnabled'. Either include them or remove the dependency array

const handleClickWalkThrough = () => {
setIsWalkthrough( true );
};

useEffect( () => {
getSiteDetails();
}, [] );

async function getSiteDetails() {
try {
let siteDetailsmetas = await getSiteDetailsQuestionare();
siteDetailsmetas = siteDetailsmetas.body;
setSiteDetailsmeta( siteDetailsmetas );
} catch ( err ) {
// eslint-disable-next-line no-console
console.error( 'Error fetching data:', err );
}
}

return (
<CommonLayout isCentered>
<Animate type={ 'fade-in' }>
<div className={ 'nfd-sg-site-details' }>
<AIHeading title={ content.heading } />
<TextInputSiteGen
placeholder={ content.inputPlaceholder }
hint={ content.inputHint }
height={ '40px' }
customerInput={ customerInput }
setIsValidInput={ setIsValidInput }
setCustomerInput={ setCustomerInput }
{ isWalkthrough ? (
<SiteGenSiteDetailsWalkthrough
siteDetailsmeta={ siteDetailsmeta }
/>
{ isLargeViewport && (
<div className={ 'nfd-sg-site-details-endrow' }>
<NextButtonSiteGen
className={ 'nfd-sg-site-details--next-btn' }
text={ content.buttonText }
disabled={ ! isValidInput }
/>
) : (
<div className={ 'nfd-sg-site-details' }>
<AIHeading title={ content.heading } />
<TextInputSiteGen
placeholder={ content.inputPlaceholder }
hint={ content.inputHint }
height={ '40px' }
customerInput={ customerInput }
setIsValidInput={ setIsValidInput }
setCustomerInput={ setCustomerInput }
/>
{ isLargeViewport && (
<>
<div className={ 'nfd-sg-site-details-endrow' }>
<NextButtonSiteGen
className={
'nfd-sg-site-details--next-btn'
}
text={ content.buttonText }
disabled={ ! isValidInput }
/>
</div>
</>
) }
<div className={ 'nfd-sg-site-details-walkThrough' }>
{ content.walkThroughText }
<span
onClick={ handleClickWalkThrough }
onKeyDown={ handleClickWalkThrough }
role="button"
tabIndex="0"
>
{ content.walkThroughlink }
</span>
</div>
) }
</div>
</div>
) }
</Animate>
</CommonLayout>
);
Expand Down
Loading