SettingsMenu.utils.tsx171 lines · main
| 1 | import { useFlag, useParams } from 'common' |
| 2 | import { ArrowUpRight } from 'lucide-react' |
| 3 | |
| 4 | import { useIsPlatformWebhooksEnabled } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext' |
| 5 | import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled' |
| 6 | import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization' |
| 7 | import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' |
| 8 | import { IS_PLATFORM, PROJECT_STATUS } from '@/lib/constants' |
| 9 | |
| 10 | export const useGenerateSettingsMenu = () => { |
| 11 | const { ref } = useParams() |
| 12 | const { data: project } = useSelectedProjectQuery() |
| 13 | const { data: organization } = useSelectedOrganizationQuery() |
| 14 | const showDashboardPreferences = useFlag('dashboardPreferences') |
| 15 | |
| 16 | const platformWebhooksEnabled = useIsPlatformWebhooksEnabled() |
| 17 | |
| 18 | const { projectSettingsLegacyJwtKeys: legacyJwtKeysEnabled, billingAll: billingEnabled } = |
| 19 | useIsFeatureEnabled(['project_settings:legacy_jwt_keys', 'billing:all']) |
| 20 | |
| 21 | const isProjectActive = project?.status === PROJECT_STATUS.ACTIVE_HEALTHY |
| 22 | |
| 23 | if (!IS_PLATFORM) { |
| 24 | return [ |
| 25 | { |
| 26 | title: 'Configuration', |
| 27 | items: [ |
| 28 | { |
| 29 | name: `Log Drains`, |
| 30 | key: `log-drains`, |
| 31 | url: `/project/${ref}/settings/log-drains`, |
| 32 | items: [], |
| 33 | }, |
| 34 | ], |
| 35 | }, |
| 36 | ] |
| 37 | } |
| 38 | |
| 39 | return [ |
| 40 | { |
| 41 | title: 'Configuration', |
| 42 | items: [ |
| 43 | { |
| 44 | name: 'General', |
| 45 | key: 'general', |
| 46 | url: `/project/${ref}/settings/general`, |
| 47 | items: [], |
| 48 | }, |
| 49 | { |
| 50 | name: 'Compute and Disk', |
| 51 | key: 'compute-and-disk', |
| 52 | url: `/project/${ref}/settings/compute-and-disk`, |
| 53 | items: [], |
| 54 | disabled: !isProjectActive, |
| 55 | }, |
| 56 | { |
| 57 | name: 'Infrastructure', |
| 58 | key: 'infrastructure', |
| 59 | url: `/project/${ref}/settings/infrastructure`, |
| 60 | items: [], |
| 61 | disabled: !isProjectActive, |
| 62 | }, |
| 63 | |
| 64 | { |
| 65 | name: 'Integrations', |
| 66 | key: 'integrations', |
| 67 | url: `/project/${ref}/settings/integrations`, |
| 68 | items: [], |
| 69 | disabled: !isProjectActive, |
| 70 | }, |
| 71 | ...(platformWebhooksEnabled |
| 72 | ? [ |
| 73 | { |
| 74 | name: 'Webhooks', |
| 75 | key: 'webhooks', |
| 76 | url: `/project/${ref}/settings/webhooks`, |
| 77 | items: [], |
| 78 | disabled: !isProjectActive, |
| 79 | }, |
| 80 | ] |
| 81 | : []), |
| 82 | |
| 83 | { |
| 84 | name: 'API Keys', |
| 85 | key: 'api-keys', |
| 86 | url: `/project/${ref}/settings/api-keys`, |
| 87 | items: [], |
| 88 | disabled: !isProjectActive, |
| 89 | }, |
| 90 | { |
| 91 | name: 'JWT Keys', |
| 92 | key: 'jwt', |
| 93 | url: legacyJwtKeysEnabled |
| 94 | ? `/project/${ref}/settings/jwt` |
| 95 | : `/project/${ref}/settings/jwt/signing-keys`, |
| 96 | items: [], |
| 97 | disabled: !isProjectActive, |
| 98 | }, |
| 99 | |
| 100 | { |
| 101 | name: `Log Drains`, |
| 102 | key: `log-drains`, |
| 103 | url: `/project/${ref}/settings/log-drains`, |
| 104 | items: [], |
| 105 | disabled: !isProjectActive, |
| 106 | }, |
| 107 | { |
| 108 | name: 'Add-ons', |
| 109 | key: 'addons', |
| 110 | url: `/project/${ref}/settings/addons`, |
| 111 | items: [], |
| 112 | }, |
| 113 | ...(showDashboardPreferences |
| 114 | ? [ |
| 115 | { |
| 116 | name: 'Dashboard', |
| 117 | key: 'dashboard', |
| 118 | url: `/project/${ref}/settings/dashboard`, |
| 119 | items: [], |
| 120 | }, |
| 121 | ] |
| 122 | : []), |
| 123 | ], |
| 124 | }, |
| 125 | { |
| 126 | title: 'Integrations', |
| 127 | items: [ |
| 128 | { |
| 129 | name: 'Data API', |
| 130 | key: 'api', |
| 131 | url: `/project/${ref}/integrations/data_api/overview`, |
| 132 | items: [], |
| 133 | rightIcon: <ArrowUpRight strokeWidth={1} className="h-4 w-4" />, |
| 134 | disabled: !isProjectActive, |
| 135 | }, |
| 136 | { |
| 137 | name: 'Vault', |
| 138 | key: 'vault', |
| 139 | url: `/project/${ref}/integrations/vault/overview`, |
| 140 | items: [], |
| 141 | rightIcon: <ArrowUpRight strokeWidth={1} className="h-4 w-4" />, |
| 142 | label: 'Beta', |
| 143 | disabled: !isProjectActive, |
| 144 | }, |
| 145 | ], |
| 146 | }, |
| 147 | { |
| 148 | title: 'Billing', |
| 149 | items: [ |
| 150 | ...(billingEnabled |
| 151 | ? [ |
| 152 | { |
| 153 | name: 'Subscription', |
| 154 | key: 'subscription', |
| 155 | url: `/org/${organization?.slug}/billing`, |
| 156 | items: [], |
| 157 | rightIcon: <ArrowUpRight strokeWidth={1} className="h-4 w-4" />, |
| 158 | }, |
| 159 | ] |
| 160 | : []), |
| 161 | { |
| 162 | name: 'Usage', |
| 163 | key: 'usage', |
| 164 | url: `/org/${organization?.slug}/usage?projectRef=${ref}`, |
| 165 | items: [], |
| 166 | rightIcon: <ArrowUpRight strokeWidth={1} className="h-4 w-4" />, |
| 167 | }, |
| 168 | ], |
| 169 | }, |
| 170 | ] |
| 171 | } |