app
1 year ago
receipt
1 year ago
registrars
1 year ago
shared
2 years ago
styles
1 year ago
embed.ts
2 years ago
embedInside.ts
2 years ago
entity.ts
1 year ago
propTypes.ts
1 year ago
types.ts
2 years ago
utils.ts
1 year ago
utils.ts
52 lines
| 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 | }; |
| 19 | } |
| 20 | |
| 21 | type useFormsParams = { |
| 22 | ids?: number[], |
| 23 | page?: number, |
| 24 | per_page?: number; |
| 25 | status?: FormStatus[] |
| 26 | } |
| 27 | |
| 28 | export function useForms({ |
| 29 | ids = [], |
| 30 | page = 1, |
| 31 | per_page = 30, |
| 32 | status = ['publish'] |
| 33 | }: useFormsParams = {}) { |
| 34 | const data = useEntityRecords('givewp', 'form', { |
| 35 | ids, |
| 36 | page, |
| 37 | per_page, |
| 38 | status |
| 39 | }); |
| 40 | |
| 41 | return { |
| 42 | forms: data?.records as Form[], |
| 43 | //@ts-ignore |
| 44 | totalItems: data.totalItems, |
| 45 | //@ts-ignore |
| 46 | totalPages: data.totalPages, |
| 47 | hasResolved: data?.hasResolved, |
| 48 | }; |
| 49 | } |
| 50 | |
| 51 | |
| 52 |