Skip to content
Snippets Groups Projects
Commit 69a15047 authored by Guilhem CARRON's avatar Guilhem CARRON
Browse files

test

parent c735be0c
No related branches found
No related tags found
2 merge requests!7feat: add front office,!6Test variabilisation
version: '3.7' version: '3.7'
services: services:
nginx: nginx:
image: registry.forge.grandlyon.com/web-et-numerique/llle_project/backoffice-client:dev image: test
restart: unless-stopped restart: unless-stopped
ports: ports:
- 443:443 - 443:443
...@@ -29,7 +29,7 @@ services: ...@@ -29,7 +29,7 @@ services:
retries: 60 retries: 60
backend: backend:
image: registry.forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server:dev image: registry.forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server:back
networks: networks:
backoffice: backoffice:
depends_on: depends_on:
......
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<base href="%PUBLIC_URL%/">
<meta charset="utf-8" /> <meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
......
...@@ -10,7 +10,7 @@ function App() { ...@@ -10,7 +10,7 @@ function App() {
const { user, setUser, isLoading } = useFindUser() const { user, setUser, isLoading } = useFindUser()
return ( return (
<BrowserRouter> <BrowserRouter basename={process.env.PUBLIC_URL}>
<UserContext.Provider value={{ user, setUser, isLoading }}> <UserContext.Provider value={{ user, setUser, isLoading }}>
<Layout> <Layout>
<Routes /> <Routes />
......
...@@ -3,8 +3,6 @@ import axios from 'axios' ...@@ -3,8 +3,6 @@ import axios from 'axios'
import { UserContext } from './userContext' import { UserContext } from './userContext'
import { useHistory } from 'react-router-dom' import { useHistory } from 'react-router-dom'
const _apiUrl: string = 'https://localhost:443/'
export interface Auth { export interface Auth {
loginUser: () => Promise<void> loginUser: () => Promise<void>
error: null error: null
...@@ -18,7 +16,9 @@ export const useAuth = (): Auth => { ...@@ -18,7 +16,9 @@ export const useAuth = (): Auth => {
//login user //login user
const loginUser = async (): Promise<void> => { const loginUser = async (): Promise<void> => {
try { try {
await axios.get(`${_apiUrl}OAuth2Login`, { withCredentials: true }) await axios.get(`${process.env.PUBLIC_URL}OAuth2Login`, {
withCredentials: true,
})
await setUserContext() await setUserContext()
} catch (e) { } catch (e) {
setError(e) setError(e)
...@@ -28,7 +28,7 @@ export const useAuth = (): Auth => { ...@@ -28,7 +28,7 @@ export const useAuth = (): Auth => {
const logoutUser = async (): Promise<void> => { const logoutUser = async (): Promise<void> => {
try { try {
if (setUser) setUser(null) if (setUser) setUser(null)
await axios.get(`${_apiUrl}Logout`) await axios.get(`${process.env.PUBLIC_URL}Logout`)
} catch (e) { } catch (e) {
setError(e) setError(e)
} }
...@@ -37,9 +37,12 @@ export const useAuth = (): Auth => { ...@@ -37,9 +37,12 @@ export const useAuth = (): Auth => {
//set user in context and push them home //set user in context and push them home
const setUserContext = async (): Promise<void> => { const setUserContext = async (): Promise<void> => {
try { try {
const { data } = await axios.get(`${_apiUrl}api/common/WhoAmI`, { const { data } = await axios.get(
withCredentials: true, `${process.env.PUBLIC_URL}api/common/WhoAmI`,
}) {
withCredentials: true,
}
)
if (data && setUser) { if (data && setUser) {
setUser(data) setUser(data)
history.push('/editing') history.push('/editing')
......
...@@ -5,11 +5,12 @@ import { User } from '../models/user.model' ...@@ -5,11 +5,12 @@ import { User } from '../models/user.model'
const useFindUser = () => { const useFindUser = () => {
const [user, setUser] = useState<User | null>(null) const [user, setUser] = useState<User | null>(null)
const [isLoading, setLoading] = useState<boolean>(true) const [isLoading, setLoading] = useState<boolean>(true)
const _apiUrl: string = 'https://localhost:443/'
useEffect(() => { useEffect(() => {
async function findUser() { async function findUser() {
const { data } = await axios.get(`${_apiUrl}api/common/WhoAmI`) const { data } = await axios.get(
`${process.env.PUBLIC_URL}api/common/WhoAmI`
)
if (data) { if (data) {
setUser(data) setUser(data)
setLoading(false) setLoading(false)
......
...@@ -21,7 +21,7 @@ export class MonthlyNewsService { ...@@ -21,7 +21,7 @@ export class MonthlyNewsService {
): Promise<void> => { ): Promise<void> => {
try { try {
await axios.put( await axios.put(
`${this._apiUrl}api/admin/monthlyNews`, `${process.env.PUBLIC_URL}/api/admin/monthlyNews`,
{ {
month: date.getMonth(), month: date.getMonth(),
year: date.getFullYear(), year: date.getFullYear(),
...@@ -51,17 +51,13 @@ export class MonthlyNewsService { ...@@ -51,17 +51,13 @@ export class MonthlyNewsService {
): Promise<IMonthlyNews | null> => { ): Promise<IMonthlyNews | null> => {
try { try {
const { data } = await axios.get( const { data } = await axios.get(
`${this._apiUrl}api/admin/monthlyNews/${year}/${month}`, `${process.env.PUBLIC_URL}/api/admin/monthlyNews/${year}/${month}`,
{ {
headers: { headers: {
'XSRF-TOKEN': token, 'XSRF-TOKEN': token,
}, },
} }
) )
// if (data == {}) {
// return null
// }
return data as IMonthlyNews return data as IMonthlyNews
} catch (e) { } catch (e) {
console.log('error', e) console.log('error', e)
...@@ -79,16 +75,13 @@ export class MonthlyNewsService { ...@@ -79,16 +75,13 @@ export class MonthlyNewsService {
): Promise<IPoll | null> => { ): Promise<IPoll | null> => {
try { try {
const { data } = await axios.get( const { data } = await axios.get(
`${this._apiUrl}api/admin/poll/${year}/${month}`, `${process.env.PUBLIC_URL}/api/admin/poll/${year}/${month}`,
{ {
headers: { headers: {
'XSRF-TOKEN': token, 'XSRF-TOKEN': token,
}, },
} }
) )
// if (data === {}) {
// return null
// }
return data as IPoll return data as IPoll
} catch (e) { } catch (e) {
console.log('error', e) console.log('error', e)
...@@ -110,7 +103,7 @@ export class MonthlyNewsService { ...@@ -110,7 +103,7 @@ export class MonthlyNewsService {
): Promise<void> => { ): Promise<void> => {
try { try {
await axios.put( await axios.put(
`${this._apiUrl}api/admin/poll`, `${process.env.PUBLIC_URL}/api/admin/poll`,
{ {
month: date.getMonth(), month: date.getMonth(),
year: date.getFullYear(), year: date.getFullYear(),
...@@ -141,11 +134,14 @@ export class MonthlyNewsService { ...@@ -141,11 +134,14 @@ export class MonthlyNewsService {
token: string token: string
): Promise<void> => { ): Promise<void> => {
try { try {
await axios.delete(`${this._apiUrl}api/admin/poll/${year}/${month}`, { await axios.delete(
headers: { `${process.env.PUBLIC_URL}api/admin/poll/${year}/${month}`,
'XSRF-TOKEN': token, {
}, headers: {
}) 'XSRF-TOKEN': token,
},
}
)
toast.success('Poll succesfully deleted !') toast.success('Poll succesfully deleted !')
} catch (e) { } catch (e) {
toast.error('Failed to delete poll') toast.error('Failed to delete poll')
...@@ -165,7 +161,7 @@ export class MonthlyNewsService { ...@@ -165,7 +161,7 @@ export class MonthlyNewsService {
): Promise<void> => { ): Promise<void> => {
try { try {
await axios.delete( await axios.delete(
`${this._apiUrl}api/admin/monthlyNews/${year}/${month}`, `${process.env.PUBLIC_URL}api/admin/monthlyNews/${year}/${month}`,
{ {
headers: { headers: {
'XSRF-TOKEN': token, 'XSRF-TOKEN': token,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment