Skip to content
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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export namespace API {

let obj = await db.findObject(collection, query);
if (!obj) {
obj = {};
obj = false;
}

res.status(200).send(obj);
Expand Down
99 changes: 97 additions & 2 deletions pages/createTeam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

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



const searchTeam = async () => {
if (!teamNumber) {
Expand Down Expand Up @@ -50,6 +55,7 @@ export default function CreateTeam() {
};

const createTeam = async (league: League) => {
setError("")
if (!autoData || !session?.user) {
return;
}
Expand Down Expand Up @@ -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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use NotLinkedToTba. It's a constant in ClientUtils.ts.

league
);
console.log("Created")
const win: Window = window;
win.location = `/${newTeam.slug}`;
}

useEffect(() => {
searchTeam();
}, [teamNumber]);
Expand All @@ -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>
Copy link
Contributor

Choose a reason for hiding this comment

The 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"

Copy link
Contributor

Choose a reason for hiding this comment

The 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"
Expand All @@ -120,6 +183,7 @@ export default function CreateTeam() {
<div onClick={() => createTeam(League.FRC)}>
<TeamCard team={autoData} />
</div>

}
{ ftcAutoData?.name &&
<div onClick={() => createTeam(League.FTC)}>
Expand All @@ -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)"
Copy link
Contributor

Choose a reason for hiding this comment

The 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>
);
Expand Down
Loading