-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
414 additions
and
26 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
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,41 @@ | ||
.ChoiceNotification { | ||
position: fixed; | ||
left: 50%; | ||
top: 50%; | ||
transform: translate(-50%, -50%); | ||
background-color: var(--btn-color); | ||
width: 400px; | ||
height: 200px; | ||
border-radius: 10px; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
border: 2px solid var(--text-color); | ||
color: var(--text-color); | ||
box-shadow: 0 0 10px var(--text-color); | ||
h1 { | ||
margin-top: 40px; | ||
margin-bottom: 10px; | ||
} | ||
button { | ||
background-color: transparent; | ||
color: var(--text-color); | ||
border: 2px solid var(--text-color); | ||
border-radius: 5px; | ||
padding: 5px; | ||
padding-left: 20px; | ||
padding-right: 20px; | ||
font-size: 20px; | ||
cursor: pointer; | ||
&:hover { | ||
background-color: var(--text-color); | ||
color: var(--bg-color); | ||
scale: 1.1; | ||
} | ||
} | ||
.choiceBtns { | ||
display: flex; | ||
justify-content: space-around; | ||
width: 100%; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/components/ChoiceNotification/ChoiceNotification.test.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,3 @@ | ||
test('ChoiceNotificationTest', () => { | ||
expect(true).toBe(true); | ||
}); |
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,40 @@ | ||
import './ChoiceNotification.scss'; | ||
|
||
interface Props { | ||
heading: string; | ||
info: string; | ||
onAccept: () => void; | ||
onReject: () => void; | ||
acceptText: string; | ||
rejectText: string; | ||
} | ||
|
||
/** | ||
* A notification that is displayed to the user | ||
* @param heading The heading of the notification | ||
* @param info More information about the notification | ||
* @param onClose The function to call when the notification is closed | ||
*/ | ||
function ChoiceNotification({ | ||
heading, | ||
info, | ||
onAccept, | ||
onReject, | ||
acceptText = 'Yes', | ||
rejectText = 'No', | ||
}: Props) { | ||
return ( | ||
<div> | ||
<div className="background" onClick={onReject}></div> | ||
<div className="ChoiceNotification"> | ||
<h1>{heading}</h1> | ||
<p>{info}</p> | ||
<div className="choiceBtns"> | ||
<button onClick={onReject}>{rejectText}</button> | ||
<button onClick={onAccept}>{acceptText}</button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
export default ChoiceNotification; |
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,43 @@ | ||
.CreateOrg { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
width: 100%; | ||
height: 100%; | ||
padding-top: 100px; | ||
h1 { | ||
text-align: center; | ||
} | ||
.errorMsg { | ||
color: red; | ||
font-size: 15px; | ||
font-weight: bold; | ||
text-align: center; | ||
border: none; | ||
box-shadow: none; | ||
min-height: 20px; | ||
} | ||
div { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
* { | ||
margin: 10px; | ||
} | ||
input { | ||
width: 300px; | ||
height: 30px; | ||
border-radius: 5px; | ||
text-align: center; | ||
font-size: 20px; | ||
background-color: var(--btn-color); | ||
border: 2px solid var(--btn-color); | ||
color: var(--text-color); | ||
&:focus { | ||
outline: none; | ||
border: 2px solid #083d60; | ||
} | ||
} | ||
} | ||
} |
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,3 @@ | ||
test('CreateOrgTest', () => { | ||
expect(true).toBe(true); | ||
}); |
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,85 @@ | ||
import { Link, useNavigate } from 'react-router-dom'; | ||
import './CreateOrg.scss'; | ||
import { useGetUsername, useLoggedIn } from '../../providers/UserProvider'; | ||
import { useEffect, useState } from 'react'; | ||
import APIService from '../../utils/ApiService'; | ||
import { useShowNotification } from '../../providers/NotificationProvider'; | ||
|
||
/** | ||
* A page to create an organization | ||
*/ | ||
function CreateOrg() { | ||
const [errorMessage, setErrorMessage] = useState(' '); | ||
const [name, setName] = useState(''); | ||
|
||
const navigate = useNavigate(); | ||
const showNotification = useShowNotification(); | ||
|
||
const getUserName = useGetUsername(); | ||
const isLoggedIn = useLoggedIn(); | ||
|
||
const [username] = useState(getUserName()); | ||
|
||
const onCreateOrg = () => { | ||
if (name === '') { | ||
setErrorMessage('Organization name cannot be empty'); | ||
return; | ||
} | ||
if (name.length > 20) { | ||
setErrorMessage( | ||
'Organization name cannot be longer than 20 characters' | ||
); | ||
return; | ||
} | ||
if (name.length < 3) { | ||
setErrorMessage( | ||
'Organization name cannot be shorter than 3 characters' | ||
); | ||
return; | ||
} | ||
APIService.createOrg(username, name).then((suc) => { | ||
if (!suc) { | ||
setErrorMessage('Organization already exists'); | ||
return; | ||
} | ||
showNotification( | ||
'Organization created!', | ||
'Organization ' + name + ' created successfully.' | ||
); | ||
navigate('/profile'); | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
if (!isLoggedIn) { | ||
navigate('/'); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [isLoggedIn, username]); | ||
|
||
return ( | ||
<div className="CreateOrg"> | ||
<h1> | ||
wanna<span className="db">db</span> <br /> | ||
<i>CREATE ORGANIZATION</i> | ||
</h1> | ||
<div> | ||
<p className="errorMsg">{errorMessage}</p> | ||
<input | ||
type="text" | ||
placeholder="Organization Name" | ||
value={name} | ||
onChange={(e) => setName(e.target.value)} | ||
/> | ||
|
||
<button className="btn" onClick={onCreateOrg}> | ||
Create | ||
</button> | ||
<Link className="btn" to="/profile"> | ||
Back | ||
</Link> | ||
</div> | ||
</div> | ||
); | ||
} | ||
export default CreateOrg; |
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 |
---|---|---|
|
@@ -9,4 +9,10 @@ | |
font-weight: bold; | ||
margin-bottom: 20px; | ||
} | ||
.orgBtns { | ||
display: flex; | ||
* { | ||
margin-right: 10px; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.