You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

use-credential-status.ts 968B

1234567891011121314151617181920212223242526
  1. import { useMemo } from 'react'
  2. import type {
  3. ModelProvider,
  4. } from '../../declarations'
  5. export const useCredentialStatus = (provider: ModelProvider) => {
  6. const {
  7. current_credential_id,
  8. current_credential_name,
  9. available_credentials,
  10. } = provider.custom_configuration
  11. const hasCredential = !!available_credentials?.length
  12. const authorized = current_credential_id && current_credential_name
  13. const authRemoved = hasCredential && !current_credential_id && !current_credential_name
  14. const currentCredential = available_credentials?.find(credential => credential.credential_id === current_credential_id)
  15. return useMemo(() => ({
  16. hasCredential,
  17. authorized,
  18. authRemoved,
  19. current_credential_id,
  20. current_credential_name,
  21. available_credentials,
  22. notAllowedToUse: currentCredential?.not_allowed_to_use,
  23. }), [hasCredential, authorized, authRemoved, current_credential_id, current_credential_name, available_credentials])
  24. }