-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scouting alliance #218
Scouting alliance #218
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,11 @@ export default function CreateTeam() { | |
const [ftcAutoData, setFtcAutoData] = useState<Team>(); | ||
const [loading, setLoading] = useState(false); | ||
const [error, setError] = useState(""); | ||
const [allianceNumber,setAllianceNumber] = useState<number>(); | ||
const [allianceName, setAllianceName] = useState<string>(); | ||
const [creatingTeam, setCreatingTeam] = useState<boolean>(); | ||
const [settingState, setSettingState] = useState<boolean>(true) | ||
|
||
|
||
const searchTeam = async () => { | ||
if (!teamNumber) { | ||
|
@@ -50,6 +55,7 @@ export default function CreateTeam() { | |
}; | ||
|
||
const createTeam = async (league: League) => { | ||
setError("") | ||
if (!autoData || !session?.user) { | ||
return; | ||
} | ||
|
@@ -82,6 +88,47 @@ export default function CreateTeam() { | |
win.location = `/${newTeam.slug}`; | ||
}; | ||
|
||
async function createAlliance(league: League){ | ||
setError("") | ||
console.log("Beginning Alliance Creation") | ||
if (!session?.user) { | ||
return; | ||
} | ||
|
||
|
||
if ( | ||
await api.findTeamByNumberAndLeague(Number(allianceNumber), league) | ||
) { | ||
console.log(allianceNumber) | ||
console.log(league) | ||
setError("This Team Already Exists"); | ||
return; | ||
} | ||
|
||
if (allianceNumber?.toString().length!=7){ | ||
setError("Alliances must have a seven digit number") | ||
return | ||
} | ||
|
||
if(!allianceName) { | ||
setError("Your alliance must have a name") | ||
return | ||
} | ||
console.log("Made part 2") | ||
|
||
|
||
const newTeam = await api.createTeam( | ||
allianceName, | ||
allianceNumber!, | ||
session.user._id, | ||
"none", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
league | ||
); | ||
console.log("Created") | ||
const win: Window = window; | ||
win.location = `/${newTeam.slug}`; | ||
} | ||
|
||
useEffect(() => { | ||
searchTeam(); | ||
}, [teamNumber]); | ||
|
@@ -94,11 +141,27 @@ export default function CreateTeam() { | |
mode="col" | ||
className="md:h-full items-center md:justify-center max-sm:py-10" | ||
> | ||
<Card title="Create a Team" className=""> | ||
{settingState ? | ||
<Card title="Create an Organization" className=""> | ||
<div className="divider"></div> | ||
<div className="btn btn-primary" onClick={()=>{ | ||
setSettingState(false) | ||
setCreatingTeam(false) | ||
}}>Create an Alliance</div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to "Create an alliance" because the other option is "Create a team" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should change it to be undefined at some point though. |
||
<div></div> | ||
<div className="btn btn-primary" onClick={()=>{ | ||
setSettingState(false) | ||
setCreatingTeam(true) | ||
}}>Create a team</div> | ||
</Card> | ||
: | ||
|
||
creatingTeam? <Card title="Create a Team" className=""> | ||
<h1 className="font-semibold text-accent md:ml-4"> | ||
Search our database with your teams number | ||
</h1> | ||
<h1 className="text-error">{error}</h1> | ||
<div className="btn btn-primary" onClick={()=>setSettingState(true)}>Go Back</div> | ||
<div className="divider"></div> | ||
<input | ||
className="input input-bordered md:w-1/2" | ||
|
@@ -120,6 +183,7 @@ export default function CreateTeam() { | |
<div onClick={() => createTeam(League.FRC)}> | ||
<TeamCard team={autoData} /> | ||
</div> | ||
|
||
} | ||
{ ftcAutoData?.name && | ||
<div onClick={() => createTeam(League.FTC)}> | ||
|
@@ -130,7 +194,38 @@ export default function CreateTeam() { | |
)} | ||
</div> | ||
)} | ||
</Card> | ||
</Card> | ||
|
||
: | ||
|
||
<Card title="Create an Alliance" className=""> | ||
<h1 className="font-semibold text-accent md:ml-4"> | ||
Create your Scouting Alliance | ||
</h1> | ||
<h1 className="text-error">{error}</h1> | ||
<div className="btn btn-primary" onClick={()=>setSettingState(true)}>Go Back</div> | ||
<div className="divider"></div> | ||
<input | ||
className="input input-bordered md:w-1/2" | ||
placeholder="Alliance ID (7 characters)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change Alliance ID to Alliance Number or something similar, so users know it should be a number. Also add a type attribute to the input so users can't enter letters. Entering letters breaks the page right now. |
||
maxLength={7} | ||
minLength={7} | ||
value={allianceNumber} | ||
onChange={(e) => { | ||
setAllianceNumber(Number(e.target.value)); | ||
}} | ||
></input> | ||
<input | ||
className="input input-bordered md:w-1/2" | ||
placeholder="Alliance Name" | ||
value={allianceName} | ||
onChange={(e) => { | ||
setAllianceName(e.target.value); | ||
}} | ||
></input> | ||
<div></div> | ||
<div className="btn btn-secondary" onClick={() => createAlliance(League.FRC)}>Create Alliance</div> | ||
</Card>} | ||
</Flex> | ||
</Container> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a more descriptive name