PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / DonationForms / resources / utils.ts

utils.ts in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/DonationForms/resources/utils.ts

54 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {useEntityRecord, useEntityRecords} from '@wordpress/core-data';
2 import {Form} from './types'
3
4
5 type FormStatus = "draft" | "publish" | "private" | "orphaned";
6
7 /**
8 * @since 4.2.0
9 */
10 export function useForm(formId: number) {
11 const data = useEntityRecord('givewp', 'forms', formId);
12
13 return {
14 form: {
15 ...data?.record as Form
16 },
17 hasResolved: data?.hasResolved,
18 isResolving: data?.isResolving,
19 };
20 }
21
22 type useFormsParams = {
23 ids?: number[],
24 page?: number,
25 per_page?: number;
26 status?: FormStatus[]
27 }
28
29 export function useForms({
30 ids = [],
31 page = 1,
32 per_page = 30,
33 status = ['publish']
34 }: useFormsParams = {}) {
35 const data = useEntityRecords('givewp', 'form', {
36 ids,
37 page,
38 per_page,
39 status
40 });
41
42 return {
43 forms: data?.records as Form[],
44 //@ts-ignore
45 totalItems: data.totalItems,
46 //@ts-ignore
47 totalPages: data.totalPages,
48 hasResolved: data?.hasResolved,
49 isResolving: data?.isResolving,
50 };
51 }
52
53
54