Skip to content
Snippets Groups Projects
Commit a8159232 authored by Princelle Maxime's avatar Princelle Maxime :gay_pride_flag:
Browse files

:sparkles: implement student api

parent 913e54a8
Branches
1 merge request!7🔀 V1
......@@ -51,7 +51,9 @@ steps:
script:
- cd /app/uni/erp/rms
- echo -e "REACT_APP_BACK_API_KEY=theapikey" > .env
- echo -e "\nREACT_APP_BACK_URL=back.erp.uni.princelle.org" >> .env
- echo -e "REACT_APP_BACK_URL=back.erp.uni.princelle.org" >> .env
- echo -e "\nREACT_APP_MONEY_URL=money.erp.uni.princelle.org" >> .env
- echo -e "\nREACT_APP_STUDENT_URL=student.erp.uni.princelle.org" >> .env
- echo -e "\nAPP_PORT=2002" >> .env
- name: build
......
REACT_APP_BACK_URL="back.erp.uni.princelle.org"
REACT_APP_MONEY_URL="money.erp.uni.princelle.org"
REACT_APP_STUDENT_URL="student.erp.uni.princelle.org"
REACT_APP_BACK_API_KEY="theapikey"
APP_PORT=8889
\ No newline at end of file
......@@ -23,4 +23,5 @@ yarn-debug.log*
yarn-error.log*
.idea
.vscode
\ No newline at end of file
.vscode
.env
\ No newline at end of file
import axios from 'axios';
import { Product } from '../cart/CartTypes';
const BASE_URL = "https://back.erp.uni.princelle.org/api/v1";
const BASE_URL = "https://" + process.env.REACT_APP_BACK_URL + "/api/v1";
// Fetch items from API
export function getItems(): Promise<Product[]> {
......@@ -9,7 +9,6 @@ export function getItems(): Promise<Product[]> {
return new Promise((resolve, reject) => {
axios.get(`${BASE_URL}/item`, {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
'apikey': APIKEY,
}
......@@ -18,7 +17,6 @@ export function getItems(): Promise<Product[]> {
let productArray: Product[] = [];
axios.get(`${BASE_URL}/stock`, {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
'apikey': APIKEY,
}
......
......@@ -5,7 +5,7 @@ export class User {
prenom: string;
email: string;
studentNumber: string;
adherant: boolean;
adherant: boolean;
picture?: string;
constructor(nom, prenom, email, studentNumber, adherant, picture?) {
......@@ -18,18 +18,16 @@ export class User {
}
}
const BASE_URL = "https://student.erp.uni.princelle.org";
const BASE_URL = "https://" + process.env.REACT_APP_STUDENT_URL;
// Fetch users from API
export function getUsers(): Promise<User[]> {
return new Promise((resolve, reject) => {
axios.get(`${BASE_URL}/api/etudiants`, {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
}
}).then(function ({ data }) {
console.log(data)
const usersArray: User[] = data.map(user => new User(
user.lastname,
user.firstname,
......
......@@ -13,7 +13,7 @@ const Users = () => {
let filteredUsers = rawUsers.filter(user => {
return user.nom.toLowerCase().includes(search.toLowerCase()) ||
user.prenom.toLowerCase().includes(search.toLowerCase()) ||
user.studentNumber.toLowerCase().includes(search.toLowerCase());
user.studentNumber.toString().toLowerCase().includes(search.toLowerCase());
});
setUsersList(filteredUsers);
}, [search, rawUsers]);
......@@ -21,6 +21,7 @@ const Users = () => {
useEffect(() => {
// Fetch users from API
getUsers().then((data) => {
console.log(data)
setRawUsers(data);
setUsersList(data);
}).catch((_) => {
......@@ -65,12 +66,6 @@ const Users = () => {
>
Nom
</th>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
Prénom
</th>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
......@@ -85,7 +80,7 @@ const Users = () => {
</th>
<th
scope="col"
className="py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
className="py-3 pr-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
Adhérent?
</th>
......@@ -94,15 +89,24 @@ const Users = () => {
<tbody>
{usersList.map((user, userIdx) => (
<tr key={user.studentNumber} className={userIdx % 2 === 0 ? 'bg-white' : 'bg-gray-50'}>
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{user.nom}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{user.prenom}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
<div className="flex items-center">
<div className="flex-shrink-0 h-10 w-10">
<img className="h-10 w-10 rounded-full" src={user.picture} alt="" />
</div>
<div className="ml-4">
<div className="text-sm font-medium text-gray-900">{user.nom.toUpperCase()}</div>
<div className="text-sm text-gray-500">{user.prenom}</div>
</div>
</div>
</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{user.email}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{user.studentNumber}</td>
<td className="py-4 whitespace-nowrap text-sm text-gray-500">{
user.adherant ? <span className="inline-flex items-center px-3 py-0.5 rounded-full text-sm font-medium bg-red-100 text-red-800">
Non
</span> : <span className="inline-flex items-center px-3 py-0.5 rounded-full text-sm font-medium bg-green-100 text-green-800">
<td className="py-4 whitespace-nowrap text-sm text-gray-500">
{user.adherant ? <span className="inline-flex items-center px-3 py-0.5 rounded-full text-sm font-medium bg-green-100 text-green-800">
Oui
</span> : <span className="inline-flex items-center px-3 py-0.5 rounded-full text-sm font-medium bg-red-100 text-red-800">
Non
</span>
}</td>
</tr>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment