2023-08-29 06:00:54 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { assign } from 'xstate';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
designWithAiStateMachineContext,
|
|
|
|
designWithAiStateMachineEvents,
|
2023-09-06 06:21:09 +00:00
|
|
|
completionAPIResponse,
|
2023-08-29 06:00:54 +00:00
|
|
|
} from './types';
|
2023-09-06 06:21:09 +00:00
|
|
|
import {
|
|
|
|
businessInfoDescriptionCompleteEvent,
|
|
|
|
lookAndFeelCompleteEvent,
|
|
|
|
toneOfVoiceCompleteEvent,
|
|
|
|
} from './pages';
|
2023-08-29 06:00:54 +00:00
|
|
|
|
|
|
|
const assignBusinessInfoDescription = assign<
|
|
|
|
designWithAiStateMachineContext,
|
|
|
|
designWithAiStateMachineEvents
|
|
|
|
>( {
|
|
|
|
businessInfoDescription: ( context, event: unknown ) => {
|
|
|
|
return {
|
|
|
|
descriptionText: ( event as businessInfoDescriptionCompleteEvent )
|
|
|
|
.payload,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
} );
|
2023-09-06 06:21:09 +00:00
|
|
|
|
|
|
|
const assignLookAndFeel = assign<
|
|
|
|
designWithAiStateMachineContext,
|
|
|
|
designWithAiStateMachineEvents
|
|
|
|
>( {
|
|
|
|
lookAndFeel: ( context, event: unknown ) => {
|
|
|
|
return {
|
|
|
|
choice: ( event as lookAndFeelCompleteEvent ).payload,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
|
|
|
const assignToneOfVoice = assign<
|
|
|
|
designWithAiStateMachineContext,
|
|
|
|
designWithAiStateMachineEvents
|
|
|
|
>( {
|
|
|
|
toneOfVoice: ( context, event: unknown ) => {
|
|
|
|
return {
|
|
|
|
choice: ( event as toneOfVoiceCompleteEvent ).payload,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
|
|
|
const assignLookAndTone = assign<
|
|
|
|
designWithAiStateMachineContext,
|
|
|
|
designWithAiStateMachineEvents
|
|
|
|
>( {
|
|
|
|
lookAndFeel: ( context, event: unknown ) => {
|
|
|
|
return {
|
|
|
|
choice: ( event as { data: completionAPIResponse } ).data.look,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
toneOfVoice: ( context, event: unknown ) => {
|
|
|
|
return {
|
|
|
|
choice: ( event as { data: completionAPIResponse } ).data.tone,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
|
|
|
const logAIAPIRequestError = () => {
|
|
|
|
// log AI API request error
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log( 'API Request error' );
|
|
|
|
};
|
|
|
|
|
2023-08-29 06:00:54 +00:00
|
|
|
export const actions = {
|
|
|
|
assignBusinessInfoDescription,
|
2023-09-06 06:21:09 +00:00
|
|
|
assignLookAndFeel,
|
|
|
|
assignToneOfVoice,
|
|
|
|
assignLookAndTone,
|
|
|
|
logAIAPIRequestError,
|
2023-08-29 06:00:54 +00:00
|
|
|
};
|