| 1 |
import {useEntityRecord} from '@wordpress/core-data'; |
| 2 |
import {Donation} from '@givewp/donations/admin/components/types'; |
| 3 |
import type {GiveDonationOptions} from '@givewp/donations/types'; |
| 4 |
|
| 5 |
declare const window: { |
| 6 |
GiveDonationOptions: GiveDonationOptions; |
| 7 |
} & Window; |
| 8 |
|
| 9 |
/** |
| 10 |
* @since 4.6.0 |
| 11 |
*/ |
| 12 |
export function useDonationEntityRecord(donationId?: number) { |
| 13 |
const urlParams = new URLSearchParams(window.location.search); |
| 14 |
|
| 15 |
const { |
| 16 |
record: donation, |
| 17 |
hasResolved, |
| 18 |
isResolving, |
| 19 |
save, |
| 20 |
edit, |
| 21 |
}: { |
| 22 |
record: Donation; |
| 23 |
hasResolved: boolean; |
| 24 |
isResolving: boolean; |
| 25 |
save: () => any; |
| 26 |
edit: (data: Donation | Partial<Donation>) => void; |
| 27 |
} = useEntityRecord('givewp', 'donation', donationId ?? urlParams.get('id')); |
| 28 |
|
| 29 |
return {record: donation, hasResolved, isResolving, save, edit}; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* @since 4.6.0 |
| 34 |
*/ |
| 35 |
export function getDonationOptionsWindowData(): GiveDonationOptions { |
| 36 |
return window.GiveDonationOptions; |
| 37 |
} |
| 38 |
|