import Badge from '@/components/ui/Badge.tsx'; import Button from '@/components/ui/Button.tsx'; import Input from '@/components/ui/Input.tsx'; import VerifiedBadge from '@/components/ui/VerifiedBadge.tsx'; import { getSectorDisplay } from '@/constants.tsx'; import { useOrganizationTable } from '@/hooks/features/useOrganizationTable.ts'; import { useTranslation } from '@/hooks/useI18n.tsx'; import { getTranslatedSectorName } from '@/lib/sector-mapper.ts'; import { getOrganizationSubtypeLabel } from '@/schemas/organizationSubtype.ts'; import { Organization } from '@/types.ts'; import { useVerifyOrganization, useRejectVerification } from '@/hooks/api/useAdminAPI.ts'; import React, { useCallback } from 'react'; interface OrganizationTableProps { onUpdateOrganization: (org: Organization) => void; } const VerifyButton = React.memo( ({ org, onVerify }: { org: Organization; onVerify: (org: Organization) => void }) => { const { t } = useTranslation(); const handleClick = useCallback(() => { onVerify(org); }, [onVerify, org]); return ( ); } ); VerifyButton.displayName = 'VerifyButton'; const OrganizationTable = ({ onUpdateOrganization }: OrganizationTableProps) => { const { t } = useTranslation(); const { filter, setFilter, searchTerm, setSearchTerm, filteredOrgs } = useOrganizationTable(); const { mutate: verifyOrganization } = useVerifyOrganization(); const { mutate: rejectVerification } = useRejectVerification(); const handleVerify = useCallback( (org: Organization) => { if (org.Verified) { // If already verified, we could reject or just update locally // For now, just update locally onUpdateOrganization({ ...org, Verified: false }); } else { verifyOrganization( { id: org.ID, notes: 'Verified via admin panel' }, { onSuccess: () => { onUpdateOrganization({ ...org, Verified: true }); }, onError: (error) => { console.error('Failed to verify organization:', error); }, } ); } }, [onUpdateOrganization, verifyOrganization] ); return (
setSearchTerm(e.target.value)} className="max-w-xs" />
{filteredOrgs.map((org) => { // Get sector display information const orgSector = org.Sector || ''; const sectorDisplay = getSectorDisplay(orgSector); return ( ); })}
{t('adminPage.orgTable.logo')} {t('adminPage.orgTable.name')} {t('adminPage.orgTable.sector')} {t('adminPage.orgTable.type')} {t('adminPage.orgTable.needsOffers')} {t('adminPage.orgTable.status')} {t('adminPage.orgTable.action')}
{org.LogoURL ? ( {`${org.Name} { (e.target as HTMLImageElement).style.display = 'none'; }} /> ) : (
{React.cloneElement(sectorDisplay.icon, { className: 'h-5 w-5 text-primary-foreground', })}
)}
{org.Name} {getTranslatedSectorName(orgSector, t)} {org.Subtype ? ( {getOrganizationSubtypeLabel(org.Subtype)} ) : ( )}
{t('adminPage.orgTable.notAvailable')}
{org.Verified ? ( ) : ( {t('adminPage.orgTable.unverified')} )}
); }; export default React.memo(OrganizationTable);