-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A4A > Feedback: Handle save feedback (#97106)
* A4A: automated feedbacks UI * show feedback after some actions are performed * logic changes * show notification only if feedback is not shown * logic update * initial API integration * wire up to existing endpoint * show success notice when feedback is successfully sent * lint fix * update success notice copy based on demo video in p2 --------- Co-authored-by: Andrii <lysenkoa.work@gmail.com> Co-authored-by: Travis Walter <travis@automattic.com>
- Loading branch information
1 parent
fc13b5f
commit ae2ce55
Showing
3 changed files
with
117 additions
and
11 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
client/a8c-for-agencies/components/a4a-feedback/hooks/use-save-feedback-mutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useMutation, UseMutationOptions, UseMutationResult } from '@tanstack/react-query'; | ||
import wpcom from 'calypso/lib/wp'; | ||
import type { MutationSaveFeedbackVariables } from '../types'; | ||
|
||
const SURVEY_ID_PREFIX = 'a4a-feedback-'; | ||
|
||
interface APIFeedback { | ||
success: boolean; | ||
err: string | null; | ||
} | ||
|
||
function mutationSaveFeedback( { params }: MutationSaveFeedbackVariables ): Promise< APIFeedback > { | ||
// Add a prefix to params.survey_id | ||
const prefixedParams = { | ||
...params, | ||
survey_id: `${ SURVEY_ID_PREFIX }${ params.survey_id }`, | ||
}; | ||
|
||
return wpcom.req.post( { | ||
apiNamespace: 'wpcom/v2', | ||
path: `/marketing/survey`, | ||
body: { ...prefixedParams }, | ||
} ); | ||
} | ||
|
||
export default function useSaveFeedbackMutation< TContext = unknown >( | ||
options?: UseMutationOptions< APIFeedback, Error, MutationSaveFeedbackVariables, TContext > | ||
): UseMutationResult< APIFeedback, Error, MutationSaveFeedbackVariables, TContext > { | ||
return useMutation< APIFeedback, Error, MutationSaveFeedbackVariables, TContext >( { | ||
...options, | ||
mutationFn: ( args ) => mutationSaveFeedback( { ...args } ), | ||
} ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters