CYS - Improve the error when a request fails due to permissions (#50211)

* Improve the error when a request fails due to permissions

* Add changefile(s) from automation for the following project(s): woocommerce

* Fix regression and copy

* Fix feedback: improve types

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Alba Rincón 2024-08-02 17:50:13 +02:00 committed by GitHub
parent 5e78db0585
commit f8854e0a4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 39 additions and 8 deletions

View File

@ -27,8 +27,15 @@ const redirectToIntroWithError = sendParent<
DesignWithoutAIStateMachineContext,
DesignWithoutAIStateMachineEvents,
DesignWithoutAIStateMachineEvents
>( {
type: 'NO_AI_FLOW_ERROR',
>( ( context, event ) => {
const errorEvent = event as {
type: string;
data?: { data?: { status: number } };
};
return {
type: 'NO_AI_FLOW_ERROR',
errorStatus: errorEvent?.data?.data?.status,
};
} );
const redirectToAssemblerHubSection = (

View File

@ -130,8 +130,13 @@ export const assignNoAIFlowError = assign<
customizeStoreStateMachineContext,
customizeStoreStateMachineEvents
>( {
intro: ( context ) => {
return { ...context.intro, hasErrors: true };
intro: ( context, event: unknown ) => {
const { errorStatus } = event as { errorStatus: number | undefined };
return {
...context.intro,
hasErrors: true,
errorStatus,
};
},
} );

View File

@ -277,6 +277,17 @@ export const Intro: CustomizeStoreComponent = ( { sendEvent, context } ) => {
context.flowType === FlowType.noAI && context.intro.hasErrors
);
const errorMessage =
context.intro.errorStatus === 403
? __(
"Sorry, you don't have permission to update the theme.",
'woocommerce'
)
: __(
'Oops! We encountered a problem while setting up the foundations. {{anchor}}Please try again{{/anchor}} or start with a theme.',
'woocommerce'
);
const [ openDesignChangeWarningModal, setOpenDesignChangeWarningModal ] =
useState( false );
@ -403,10 +414,7 @@ export const Intro: CustomizeStoreComponent = ( { sendEvent, context } ) => {
status="error"
>
{ interpolateComponents( {
mixedString: __(
'Oops! We encountered a problem while setting up the foundations. {{anchor}}Please try again{{/anchor}} or start with a theme.',
'woocommerce'
),
mixedString: errorMessage,
components: {
anchor: (
// eslint-disable-next-line jsx-a11y/anchor-has-content, jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions, jsx-a11y/anchor-is-valid

View File

@ -38,6 +38,7 @@ describe( 'Intro Banners', () => {
context={ {
intro: {
hasErrors: false,
errorStatus: undefined,
activeTheme: '',
themeData: {
themes: [],
@ -78,6 +79,7 @@ describe( 'Intro Banners', () => {
context={ {
intro: {
hasErrors: false,
errorStatus: undefined,
activeTheme: '',
themeData: {
themes: [],
@ -124,6 +126,7 @@ describe( 'Intro Banners', () => {
context={ {
intro: {
hasErrors: false,
errorStatus: undefined,
activeTheme: '',
themeData: {
themes: [],

View File

@ -36,6 +36,7 @@ describe( 'Intro Modals', () => {
context={ {
intro: {
hasErrors: false,
errorStatus: undefined,
activeTheme: '',
themeData: {
themes: [],
@ -93,6 +94,7 @@ describe( 'Intro Modals', () => {
context={ {
intro: {
hasErrors: false,
errorStatus: undefined,
activeTheme: '',
themeData: {
themes: [],
@ -148,6 +150,7 @@ describe( 'Intro Modals', () => {
context={ {
intro: {
hasErrors: false,
errorStatus: undefined,
activeTheme: '',
themeData: {
themes: [],

View File

@ -48,6 +48,7 @@ export type customizeStoreStateMachineContext = {
themeConfiguration: Record< string, unknown >; // placeholder for theme configuration until we know what it looks like
intro: {
hasErrors: boolean;
errorStatus: number | undefined;
themeData: RecommendThemesAPIResponse;
activeTheme: string;
customizeStoreTaskCompleted: boolean;

View File

@ -0,0 +1,4 @@
Significance: minor
Type: fix
CYS - Improve the error when a request fails due to permissions