components
2 days ago
hooks
2 days ago
License.jsx
2 days ago
addon-catalog.js
2 days ago
route.jsx
2 days ago
utils.js
2 days ago
License.jsx
60 lines
| 1 | /** |
| 2 | * Internal Dependencies |
| 3 | */ |
| 4 | import { EmptyState } from './components/EmptyState'; |
| 5 | import { Loader } from './components/Loader'; |
| 6 | import { LicenseItem } from './components/LicenseItem'; |
| 7 | import { |
| 8 | LicenseNotices, |
| 9 | LICENSE_NOTICES_CONTEXT, |
| 10 | } from './components/LicenseNotices'; |
| 11 | import { useLicenseData } from './hooks/useLicenseData'; |
| 12 | |
| 13 | export function License() { |
| 14 | const { licenses, appliedAddonKeyMap, hasLicenses, isLoading, error } = |
| 15 | useLicenseData(); |
| 16 | |
| 17 | if ( isLoading ) { |
| 18 | return ( |
| 19 | <> |
| 20 | <LicenseNotices isLoading={ isLoading } /> |
| 21 | <Loader /> |
| 22 | </> |
| 23 | ); |
| 24 | } |
| 25 | |
| 26 | if ( ! hasLicenses ) { |
| 27 | return ( |
| 28 | <> |
| 29 | <LicenseNotices isLoading={ isLoading } /> |
| 30 | { error?.message && ( |
| 31 | <div |
| 32 | className="mb-6 p-3 border border-red-200 bg-red-50 text-red-700 rounded" |
| 33 | role="alert" |
| 34 | > |
| 35 | { error.message } |
| 36 | </div> |
| 37 | ) } |
| 38 | <EmptyState /> |
| 39 | </> |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | return ( |
| 44 | <> |
| 45 | <LicenseNotices isLoading={ isLoading } /> |
| 46 | <div className="flex flex-col gap-6"> |
| 47 | { licenses.map( ( license ) => ( |
| 48 | <LicenseItem |
| 49 | key={ license.licenseId ?? license.licenseKey } |
| 50 | { ...license } |
| 51 | allLicenses={ licenses } |
| 52 | appliedAddonKeyMap={ appliedAddonKeyMap } |
| 53 | noticesContext={ LICENSE_NOTICES_CONTEXT } |
| 54 | /> |
| 55 | ) ) } |
| 56 | </div> |
| 57 | </> |
| 58 | ); |
| 59 | } |
| 60 |