-
Notifications
You must be signed in to change notification settings - Fork 809
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forms: Update responses management with DataViews
- Loading branch information
1 parent
7991e1b
commit 8c76076
Showing
8 changed files
with
413 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
projects/packages/forms/changelog/forms-update-responses-management
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,4 @@ | ||
Significance: minor | ||
Type: changed | ||
|
||
Forms: Update responses management with DataViews |
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
71 changes: 71 additions & 0 deletions
71
projects/packages/forms/src/dashboard/inbox/dataviews/actions/index.js
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,71 @@ | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { seen, thumbsDown, thumbsUp } from '@wordpress/icons'; | ||
import { doBulkAction } from '../../../data/responses'; | ||
import { STORE_NAME } from '../../../state'; | ||
import { ACTIONS } from '../../constants'; | ||
import InboxResponse from '../../response'; | ||
|
||
export const viewAction = { | ||
id: 'view-response', | ||
label: __( 'View response', 'jetpack-forms' ), | ||
isPrimary: true, | ||
icon: seen, | ||
RenderModal: ( { items } ) => { | ||
const [ item ] = items; | ||
return <InboxResponse isLoading={ false } response={ item } />; | ||
}, | ||
}; | ||
|
||
export const markAsSpamAction = { | ||
id: 'mark-as-spam', | ||
label: __( 'Mark as spam', 'jetpack-forms' ), | ||
isEligible: item => item.post_status !== 'spam', | ||
supportsBulk: true, | ||
icon: thumbsDown, | ||
async callback( items, { registry } ) { | ||
const itemIds = items.map( ( { id } ) => id ); | ||
const { addTabTotals, fetchResponses, removeResponses } = registry.dispatch( STORE_NAME ); | ||
Check failure on line 28 in projects/packages/forms/src/dashboard/inbox/dataviews/actions/index.js
|
||
try { | ||
removeResponses( itemIds ); | ||
// addTabTotals( { | ||
// [ currentTab ]: -1, | ||
// [ ACTION_TABS[ action ] ]: 1, | ||
// } ); | ||
// await registry | ||
// .dispatch( coreStore ) | ||
// .saveEntityRecord( | ||
// 'postType', | ||
// 'feedback', | ||
// { id: item.id, status: 'spam' }, | ||
// { throwOnError: true } | ||
// ); | ||
await doBulkAction( itemIds, ACTIONS.markAsSpam ); | ||
|
||
// await fetchResponses( | ||
// { | ||
// ...query, | ||
// limit: RESPONSES_FETCH_LIMIT, | ||
// offset: ( currentPage - 1 ) * RESPONSES_FETCH_LIMIT, | ||
// }, | ||
// { append: true } | ||
// ); | ||
} catch {} | ||
}, | ||
}; | ||
|
||
export const markAsNotSpamAction = { | ||
id: 'mark-as-not-spam', | ||
label: __( 'Not spam', 'jetpack-forms' ), | ||
isEligible: item => item.post_status === 'spam', | ||
supportsBulk: true, | ||
icon: thumbsUp, | ||
async callback( items, { registry } ) { | ||
const itemIds = items.map( ( { id } ) => id ); | ||
const { removeResponses } = registry.dispatch( STORE_NAME ); | ||
try { | ||
removeResponses( itemIds ); | ||
await doBulkAction( itemIds, ACTIONS.markAsNotSpam ); | ||
} catch {} | ||
}, | ||
}; |
Oops, something went wrong.