-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs TS-1942, TS-1829
- Loading branch information
Showing
9 changed files
with
227 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/cyberstorm/src/components/Forms/CreateTeamForm/CreateTeamForm.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.createTeamDialog { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--space--24); | ||
} | ||
|
||
.createTeamForm { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 2rem; | ||
} | ||
|
||
.createTeamDialogText { | ||
color: var(--color-text--secondary); | ||
font-weight: var(--font-weight-medium); | ||
font-size: var(--font-size--l); | ||
line-height: var(--line-height--l); | ||
} | ||
|
||
.footer { | ||
display: flex; | ||
flex-direction: row-reverse; | ||
gap: var(--gap--16); | ||
justify-content: space-between; | ||
padding-top: var(--space--16); | ||
border-top: var(--border); | ||
} | ||
|
||
.spinningIcon { | ||
animation: rotate 2s linear infinite; | ||
} | ||
|
||
@keyframes rotate { | ||
100% { | ||
transform: rotate(360deg); | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
packages/cyberstorm/src/components/Forms/CreateTeamForm/CreateTeamForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
"use client"; | ||
import styles from "./CreateTeamForm.module.css"; | ||
import * as Button from "../../Button"; | ||
import { TextInput } from "../../TextInput/TextInput"; | ||
import { useForm, FieldErrors, useController } from "react-hook-form"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { faArrowsRotate } from "@fortawesome/free-solid-svg-icons"; | ||
|
||
import { useContext } from "react"; | ||
import { ToastContext } from "../../Toast/ToastContext"; | ||
import { | ||
faCircleCheck, | ||
faCircleExclamation, | ||
faOctagonExclamation, | ||
} from "@fortawesome/pro-solid-svg-icons"; | ||
|
||
/** | ||
* Form for creating a team | ||
*/ | ||
export function CreateTeamForm() { | ||
const useToast = () => useContext(ToastContext); | ||
const toast = useToast(); | ||
|
||
async function onValid(data: { teamName: string }) { | ||
// TODO: Add sending to TS API endpoint | ||
toast?.addToast( | ||
"info", | ||
<FontAwesomeIcon icon={faCircleExclamation} />, | ||
"Creating team" | ||
); | ||
await new Promise((resolve) => { | ||
setTimeout(resolve, 1000); | ||
}); | ||
// TODO: Add a toast on response return based on the response | ||
toast?.addToast( | ||
"success", | ||
<FontAwesomeIcon icon={faCircleCheck} />, | ||
"Team created" | ||
); | ||
console.log(JSON.stringify(data)); | ||
} | ||
|
||
async function onInvalid( | ||
errors: FieldErrors<{ | ||
teamName: string; | ||
}> | ||
) { | ||
if (errors.teamName) { | ||
toast?.addToast( | ||
"danger", | ||
<FontAwesomeIcon icon={faOctagonExclamation} />, | ||
errors.teamName.message, | ||
30000 | ||
); | ||
} else { | ||
toast?.addToast( | ||
"danger", | ||
<FontAwesomeIcon icon={faOctagonExclamation} />, | ||
"Unknown error", | ||
30000 | ||
); | ||
} | ||
} | ||
|
||
const { | ||
control, | ||
handleSubmit, | ||
formState: { isSubmitting }, | ||
} = useForm<{ teamName: string }>({ | ||
mode: "onSubmit", | ||
}); | ||
|
||
const teamName = useController({ | ||
control: control, | ||
name: "teamName", | ||
rules: { | ||
required: "Team name is required", | ||
}, | ||
}); | ||
|
||
return ( | ||
<form | ||
onSubmit={handleSubmit(onValid, onInvalid)} | ||
className={styles.createTeamForm} | ||
> | ||
<div className={styles.createTeamDialog}> | ||
<div className={styles.createTeamDialogText}> | ||
Enter the name of the team you wish to create. Team names can contain | ||
the characters a-z A-Z 0-9 _ and must not start or end with an _ | ||
</div> | ||
<TextInput | ||
{...teamName.field} | ||
placeHolder={"ExampleTeamName"} | ||
color={ | ||
teamName.fieldState.isDirty | ||
? teamName.fieldState.invalid | ||
? "red" | ||
: "green" | ||
: undefined | ||
} | ||
/> | ||
</div> | ||
<div className={styles.footer}> | ||
<Button.Root type="submit" paddingSize="large" colorScheme="success"> | ||
{isSubmitting ? ( | ||
<Button.ButtonIcon iconClasses={styles.spinningIcon}> | ||
<FontAwesomeIcon icon={faArrowsRotate} /> | ||
</Button.ButtonIcon> | ||
) : ( | ||
<Button.ButtonLabel>Create</Button.ButtonLabel> | ||
)} | ||
</Button.Root> | ||
</div> | ||
</form> | ||
); | ||
} | ||
|
||
CreateTeamForm.displayName = "CreateTeamForm"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters