'use client'; import React, { useState } from 'react'; import { Card } from '@/ui/Card'; import { Button } from '@/ui/Button'; import { Input } from '@/ui/Input'; import { TextArea } from '@/ui/TextArea'; import { Box } from '@/ui/Box'; import { Stack } from '@/ui/Stack'; import { Text } from '@/ui/Text'; import { Heading } from '@/ui/Heading'; import { JoinRequestList } from '@/ui/JoinRequestList'; import { JoinRequestItem } from '@/ui/JoinRequestItem'; import { DangerZone } from '@/ui/DangerZone'; import { MinimalEmptyState } from '@/ui/EmptyState'; import { useTeamJoinRequests, useUpdateTeam, useApproveJoinRequest, useRejectJoinRequest } from "@/hooks/team"; import type { TeamJoinRequestViewModel } from '@/lib/view-models/TeamJoinRequestViewModel'; interface TeamAdminProps { team: { id: string; name: string; tag: string; description?: string; ownerId: string; }; onUpdate: () => void; } export function TeamAdmin({ team, onUpdate }: TeamAdminProps) { const [editMode, setEditMode] = useState(false); const [editedTeam, setEditedTeam] = useState({ name: team.name, tag: team.tag, description: team.description || '', }); // Use hooks for data fetching const { data: joinRequests = [], isLoading: loading } = useTeamJoinRequests( team.id, team.ownerId, true ); // Use hooks for mutations const updateTeamMutation = useUpdateTeam({ onSuccess: () => { setEditMode(false); onUpdate(); }, onError: (error) => { alert(error instanceof Error ? error.message : 'Failed to update team'); }, }); const approveJoinRequestMutation = useApproveJoinRequest({ onSuccess: () => { onUpdate(); }, onError: (error) => { alert(error instanceof Error ? error.message : 'Failed to approve request'); }, }); const rejectJoinRequestMutation = useRejectJoinRequest({ onSuccess: () => { onUpdate(); }, onError: (error) => { alert(error instanceof Error ? error.message : 'Failed to reject request'); }, }); const handleApprove = () => { // Note: The current API doesn't support approving specific requests // This would need the requestId to be passed to the service approveJoinRequestMutation.mutate(); }; const handleReject = () => { // Note: The current API doesn't support rejecting specific requests // This would need the requestId to be passed to the service rejectJoinRequestMutation.mutate(); }; const handleSaveChanges = () => { updateTeamMutation.mutate({ teamId: team.id, input: { name: editedTeam.name, tag: editedTeam.tag, description: editedTeam.description, }, }); }; return ( Team Settings {!editMode && ( )} {editMode ? ( Team Name setEditedTeam({ ...editedTeam, name: e.target.value })} /> Team Tag setEditedTeam({ ...editedTeam, tag: e.target.value })} maxLength={4} /> Max 4 characters