Skip to content

Commit

Permalink
Merge pull request #280 from COS301-SE-2022/Feature-Forms
Browse files Browse the repository at this point in the history
Bug Fixes
  • Loading branch information
jademichellepeche authored Sep 29, 2022
2 parents 5782a3c + 80f20c8 commit 86215e1
Show file tree
Hide file tree
Showing 37 changed files with 436 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ export const AcceptRejectCard: React.FC<props> = (props) =>{
color="success"
/>
<IonLoading
mode="ios"
isOpen={loading}
message={"Loading"}
duration={2000}
spinner={"circles"}
onDidDismiss={() => setLoading(false)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ const FriendRequestList: React.FC<props> = () =>{
'Content-Type': 'application/json',
},
data: JSON.stringify({
fromEmail: localStorage.getItem("email"),
toEmail: otherEmail
toEmail: otherEmail,
fromEmail: localStorage.getItem("email")

})
})
Expand Down Expand Up @@ -170,8 +170,8 @@ const FriendRequestList: React.FC<props> = () =>{
color="success"
/>
<IonLoading
mode="ios"
isOpen={loading}
message={"Loading"}
duration={2000}
spinner={"circles"}
onDidDismiss={() => setLoading(false)}
Expand Down
1 change: 0 additions & 1 deletion front-end/src/components/GymCard/GymCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@
<IonLoading
mode="ios"
isOpen={loading}
message={"Loading"}
duration={2000}
spinner={"circles"}
onDidDismiss={() => setLoading(false)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IonCol, IonGrid, IonLoading, IonRow} from '@ionic/react';
import { useEffect, useState, } from 'react';
import { IonCol, IonGrid, IonLoading, IonRow, useIonViewWillEnter} from '@ionic/react';
import { useState, } from 'react';
import ViewBadgeCard from './ViewBadgeCard/ViewBadgeCard';
import axios from 'axios';

Expand All @@ -10,12 +10,13 @@ export const GymOwnerViewBadgeGrid=(props: {gymID:string})=>{


//GET REQUEST:
useEffect(()=>
useIonViewWillEnter(()=>
{
console.log(props.gymID)
axios.get(process.env["REACT_APP_GYM_KING_API"]+`/badges/gym/${props.gymID}`)
.then(response =>response.data)
.then(response =>{
//console.log(response)
console.log(response)
let arr=[];
for(let i=0; i<response.length; i++)
{
Expand Down Expand Up @@ -50,7 +51,6 @@ export const GymOwnerViewBadgeGrid=(props: {gymID:string})=>{
<IonLoading
mode="ios"
isOpen={loading}
message={"Loading"}
duration={2000}
spinner={"circles"}
onDidDismiss={() => setLoading(false)}
Expand Down
4 changes: 3 additions & 1 deletion front-end/src/components/GymsList/GymItem/GymItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const GymsList: React.FC<props> = (props) =>{


useEffect(()=>{
console.log(props.gymId)

//get gym info
axios.get(process.env["REACT_APP_GYM_KING_API"]+`/gyms/gym/${props.gymId}`)
.then(response =>response.data)
Expand Down Expand Up @@ -62,8 +64,8 @@ const GymsList: React.FC<props> = (props) =>{
<IonLabel mode="ios">{gymName}</IonLabel>
</IonItem>
<IonLoading
mode="ios"
isOpen={loading}
message={"Loading"}
duration={2000}
spinner={"circles"}
onDidDismiss={() => setLoading(false)}
Expand Down
1 change: 0 additions & 1 deletion front-end/src/components/Register/Gym.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export const Gym: React.FC<props> = (props) =>{
<IonLoading
mode="ios"
isOpen={loading}
message={"Loading"}
duration={2000}
spinner={"circles"}
onDidDismiss={() => setLoading(false)}
Expand Down
1 change: 0 additions & 1 deletion front-end/src/components/map/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ const MapView: React.FC = () =>{
<IonLoading
mode="ios"
isOpen={loading}
message={"Loading"}
onDidDismiss={() => setLoading(false)}
spinner={"circles"}
cssClass="spinner"
Expand Down
202 changes: 120 additions & 82 deletions front-end/src/pages/AddEmployee/AddEmployee.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {IonContent, IonText, IonPage, IonHeader, IonButton, IonInput, IonToast, useIonViewDidEnter, IonLoading} from '@ionic/react';
import {IonContent, IonText, IonPage, IonHeader, IonButton, IonInput, IonToast, useIonViewDidEnter, IonLoading, IonLabel} from '@ionic/react';
import React, { useState} from 'react';
import { RadioGroup } from '../../components/radioGroup/radioGroup';
import ToolBar from '../../components/toolbar/Toolbar';
Expand Down Expand Up @@ -34,79 +34,78 @@ export const AddEmployee: React.FC = () =>{
setErrors(prevState => ({...prevState, [input]: error}));
};

// const validate = () => {
// let isValid = true
// console.log

// if(formData.email && !validEmail(formData.email)) {
// handleError('Please input a valid email', 'email');
// isValid = false;
// }
// else
// handleError('', 'email');

// if(formData.name && !onlyLettersAndSpaces(formData.name)) {
// handleError('Please input a valid name', 'name');
// isValid = false;
// }
// else
// handleError('', 'name');

// if(formData.number && !validPhone(formData.number)) {
// handleError('Please input a valid phone', 'phone');
// isValid = false;
// }
// else
// handleError('', 'phone');

// if(formData.username && !onlyAlphanumericAndUnderscore(formData.username)) {
// handleError('Please input a valid username', 'username');
// isValid = false;
// }
// else
// handleError('', 'username');

// if(formData.password && !validPassword(formData.password)) {
// handleError('Must be at least 8 characters with at least 1 uppercase, lowercase, number and symbol.', 'password');
// isValid = false;
// }
// else
// handleError('', 'password');

// if(formData.gid !=="") {
// handleError('Please select a gym.', 'gid');
// isValid = false;
// }
// else
// handleError('', 'gid');

// return isValid;
// }

// useIonViewDidEnter(()=>{
// setLoading(true)
// axios(process.env["REACT_APP_GYM_KING_API"]+`/gyms/owned/getGyms`,{
// method: 'POST',
// headers: {
// 'Accept': 'application/json',
// 'Content-Type': 'application/json',
// },
// data: JSON.stringify({
// email: localStorage.getItem("email"),
// apikey: sessionStorage.getItem("key")

// })
// })
// .then(response =>response.data)
// .then(response =>{
// setOwnedGyms(response);
// setLoading(false)
// })
// .catch(err => {
// setLoading(false)
// console.log(err)
// })
// })
const validate = () => {
let isValid = true

if(formData.email && !validEmail(formData.email)) {
handleError('Please input a valid email', 'email');
isValid = false;
}
else
handleError('', 'email');

if(formData.name && onlyLettersAndSpaces(formData.name)) {
handleError('Please input a valid name', 'name');
isValid = false;
}
else
handleError('', 'name');

if(formData.phone && !validPhone(formData.phone)) {
handleError('Please input a valid phone number', 'phone');
isValid = false;
}
else
handleError('', 'phone');

if(formData.username && !onlyAlphanumericAndUnderscore(formData.username)) {
handleError('Please input a valid username', 'username');
isValid = false;
}
else
handleError('', 'username');

if(formData.password && !validPassword(formData.password)) {
handleError('Must be at least 8 characters with at least 1 uppercase, lowercase, number and symbol.', 'password');
isValid = false;
}
else
handleError('', 'password');

if(formData.gid ==="") {
handleError('Please select a gym.', 'gid');
isValid = false;
}
else
handleError('', 'gid');

return isValid;
}

useIonViewDidEnter(()=>{
setLoading(true)
axios(process.env["REACT_APP_GYM_KING_API"]+`/gyms/owned/getGyms`,{
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
data: JSON.stringify({
email: localStorage.getItem("email"),
apikey: sessionStorage.getItem("key")

})
})
.then(response =>response.data)
.then(response =>{
setOwnedGyms(response);
setLoading(false)
})
.catch(err => {
setLoading(false)
console.log(err)
})
})

const setChosenGymLocation = (e:any) =>{
console.log(e);
Expand All @@ -124,7 +123,10 @@ export const AddEmployee: React.FC = () =>{
password: e.target.password.value,
gid: gymId,
};
createEmployee();

let isValid = validate()
if(isValid)
createEmployee();
}

const createEmployee=()=>{
Expand Down Expand Up @@ -176,22 +178,58 @@ export const AddEmployee: React.FC = () =>{
<br></br>

<IonText className="smallHeading leftMargin10">Email*</IonText>
<IonInput name='email' type='text' className='textInput smallerTextBox centerComp width80' required></IonInput><br></br>
<IonInput name='email' type='text' className='textInput smallerTextBox centerComp width80' required></IonInput>
{errors.email!=="" && (
<>
<IonLabel className="errText leftMargin10" style={{"color":"darkorange"}}>{errors.email}</IonLabel><br></br>
</>
)}
<br></br>

<IonText className="smallHeading leftMargin10">Full name*</IonText>
<IonInput name='name' type='text' className='textInput smallerTextBox centerComp width80' required></IonInput><br></br>
<IonInput name='name' type='text' className='textInput smallerTextBox centerComp width80' required></IonInput>
{errors.name!=="" && (
<>
<IonLabel className="errText leftMargin10" style={{"color":"darkorange"}}>{errors.name}</IonLabel><br></br>
</>
)}
<br></br>

<IonText className="smallHeading leftMargin10">Phone Number*</IonText>
<IonInput name='number' type='number' className='textInput smallerTextBox centerComp width80' required></IonInput><br></br>
<IonInput name='number' type='number' className='textInput smallerTextBox centerComp width80' required></IonInput>
{errors.number!=="" && (
<>
<IonLabel className="errText leftMargin10" style={{"color":"darkorange"}}>{errors.number}</IonLabel><br></br>
</>
)}
<br></br>

<IonText className="smallHeading leftMargin10"> Username*</IonText>
<IonInput name='username' type='text' className='textInput smallerTextBox centerComp width80' required></IonInput><br></br>
<IonInput name='username' type='text' className='textInput smallerTextBox centerComp width80' required></IonInput>
{errors.username!=="" && (
<>
<IonLabel className="errText leftMargin10" style={{"color":"darkorange"}}>{errors.username}</IonLabel><br></br>
</>
)}
<br></br>

<IonText className="smallHeading leftMargin10">Password*</IonText>
<IonInput name='password' type='password' className='textInput smallerTextBox centerComp width80' required></IonInput><br></br>
<IonInput name='password' type='password' className='textInput smallerTextBox centerComp width80' required></IonInput>
{errors.password!=="" && (
<>
<IonLabel className="errText leftMargin10" style={{"color":"darkorange"}}>{errors.password}</IonLabel><br></br>
</>
)}
<br></br>

<IonText className="smallHeading leftMargin10">Gym*</IonText>
<RadioGroup list={ownedGyms} chosenValue={setChosenGymLocation}></RadioGroup><br></br><br></br>
<RadioGroup list={ownedGyms} chosenValue={setChosenGymLocation}></RadioGroup>
{errors.gid!=="" && (
<>
<IonLabel className="errText leftMargin10" style={{"color":"darkorange"}}>{errors.gid}</IonLabel><br></br>
</>
)}
<br></br><br></br>

<IonButton mode="ios" color="warning" className="btnAddEmployee width80 centerComp" type="submit" expand="block">Add Employee</IonButton>

Expand Down Expand Up @@ -223,8 +261,8 @@ export const AddEmployee: React.FC = () =>{
color="danger"
/>
<IonLoading
mode="ios"
isOpen={loading}
message={"Loading"}
duration={2000}
spinner={"circles"}
onDidDismiss={() => setLoading(false)}
Expand Down
2 changes: 1 addition & 1 deletion front-end/src/pages/AddGym/AddGym.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ const AddGym: React.FC = () => {
color="danger"
/>
<IonLoading
mode="ios"
isOpen={loading}
message={"Loading"}
duration={2000}
spinner={"circles"}
onDidDismiss={() => setLoading(false)}
Expand Down
Loading

0 comments on commit 86215e1

Please sign in to comment.