import type { TeamDocument } from './CreateTeamForm'; import { httpPut } from '../../lib/http'; import { useState } from 'react'; import { NextButton } from './NextButton'; import { BuildingIcon } from '../ReactIcons/BuildingIcon.tsx'; import { UsersIcon } from '../ReactIcons/UsersIcon.tsx'; export const validTeamTypes = [ { value: 'company', label: 'Company', icon: BuildingIcon, description: 'Track the skills and learning progress of the tech team at your company', }, { value: 'study_group', label: 'Study Group', icon: UsersIcon, description: 'Invite your friends or course-mates and track your learning progress together', }, ] as const; export type ValidTeamType = (typeof validTeamTypes)[number]['value']; type Step0Props = { team?: TeamDocument; selectedTeamType: ValidTeamType; setSelectedTeamType: (teamType: ValidTeamType) => void; onStepComplete: () => void; }; export function Step0(props: Step0Props) { const { team, selectedTeamType, onStepComplete, setSelectedTeamType } = props; const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(); async function onNextClick() { if (!team) { onStepComplete(); return; } setIsLoading(true); setError(''); const { response, error } = await httpPut( `${import.meta.env.PUBLIC_API_URL}/v1-update-team/${team._id}`, { name: team.name, website: team?.links?.website || undefined, type: selectedTeamType, gitHubUrl: team?.links?.github || undefined, ...(selectedTeamType === 'company' && { teamSize: team.teamSize, linkedInUrl: team?.links?.linkedIn || undefined, }), }, ); if (error || !response) { setIsLoading(false); setError(error?.message || 'Something went wrong'); return; } setIsLoading(false); setError(''); onStepComplete(); } return ( <>
{validTeamTypes.map((validTeamType) => ( ))}
{/*Error message*/} {error &&
{error}
}
Cancel
); }