Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rede De Mentores
Frontend
Commits
27f48b4d
Unverified
Commit
27f48b4d
authored
Jul 01, 2020
by
Luis Gustavo Arseno Santana
Committed by
GitHub
Jul 01, 2020
Browse files
Merge pull request #43 from 2020-1-RDM/fix-refresh-horarioMentorias
Fix refresh horario mentorias
parents
5067e813
a29a1ab3
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/components/RedeHorarioCard/RedeHorarioCard.jsx
View file @
27f48b4d
...
@@ -10,25 +10,26 @@ import RedeMarcarMentoria from '../RedeMarcarMentoria/RedeMarcarMentoria';
...
@@ -10,25 +10,26 @@ import RedeMarcarMentoria from '../RedeMarcarMentoria/RedeMarcarMentoria';
import
{
marcarMentoria
}
from
'
../../services/mentoria
'
;
import
{
marcarMentoria
}
from
'
../../services/mentoria
'
;
function
RedeHorarioCard
({
mentoria
})
{
function
RedeHorarioCard
({
mentoria
})
{
const
[
open
,
setOpen
]
=
React
.
useState
(
false
);
const
[
open
,
setOpen
]
=
React
.
useState
(
false
);
const
[
timeInfo
,
setTimeInfo
]
=
React
.
useState
(
''
);
const
[
timeInfo
,
setTimeInfo
]
=
React
.
useState
(
''
);
const
[
dateInfo
,
setDateInfo
]
=
React
.
useState
(
''
);
const
[
dateInfo
,
setDateInfo
]
=
React
.
useState
(
''
);
const
[
mentoriaSelect
,
setMentoriaSelect
]
=
React
.
useState
(
mentoria
);
const
{
enqueueSnackbar
}
=
useSnackbar
();
const
{
enqueueSnackbar
}
=
useSnackbar
();
const
enqueue
=
(
msg
=
''
,
variant
=
'
error
'
,
autoHideDuration
=
2500
)
=>
{
const
enqueue
=
(
msg
=
''
,
variant
=
'
error
'
,
autoHideDuration
=
2500
)
=>
{
enqueueSnackbar
(
msg
,
{
variant
,
autoHideDuration
});
enqueueSnackbar
(
msg
,
{
variant
,
autoHideDuration
});
};
};
const
{
dateTime
}
=
mentoria
;
const
{
dateTime
}
=
mentoria
Select
;
const
sortedTimes
=
dateTime
.
sort
((
dateTimeA
,
dateTimeB
)
=>
dateTimeA
.
dayOfTheMonth
.
split
(
'
/
'
)[
0
]
-
dateTimeB
.
dayOfTheMonth
.
split
(
'
/
'
)[
0
])
const
sortedTimes
=
dateTime
.
sort
((
dateTimeA
,
dateTimeB
)
=>
dateTimeA
.
dayOfTheMonth
.
split
(
'
/
'
)[
0
]
-
dateTimeB
.
dayOfTheMonth
.
split
(
'
/
'
)[
0
])
.
sort
((
dateTimeA
,
dateTimeB
)
=>
dateTimeA
.
dayOfTheMonth
.
split
(
'
/
'
)[
1
]
-
dateTimeB
.
dayOfTheMonth
.
split
(
'
/
'
)[
1
]);
.
sort
((
dateTimeA
,
dateTimeB
)
=>
dateTimeA
.
dayOfTheMonth
.
split
(
'
/
'
)[
1
]
-
dateTimeB
.
dayOfTheMonth
.
split
(
'
/
'
)[
1
]);
const
timeInformation
=
sortedTimes
.
map
((
dt
)
=>
{
const
timeInformation
=
sortedTimes
.
map
((
dt
)
=>
{
// Quebra o dia onde tiver a string /, e tira os espaços em branco
// Quebra o dia onde tiver a string /, e tira os espaços em branco
let
dayOfTheMonth
=
dt
.
dayOfTheMonth
.
replace
(
/ /g
,
''
).
split
(
'
/
'
);
let
dayOfTheMonth
=
dt
.
dayOfTheMonth
.
replace
(
/ /g
,
''
).
split
(
'
/
'
);
// Loop dentro da data, se encontrar algum numero com tamanho 1, significa que precisa colocar o 0
// Loop dentro da data, se encontrar algum numero com tamanho 1,
// significa que precisa colocar o 0
// Por ex, mês 8 tem tamanho 1, precisa ficar 08
// Por ex, mês 8 tem tamanho 1, precisa ficar 08
for
(
let
i
=
0
;
i
<
2
;
i
+=
1
)
if
(
dayOfTheMonth
[
i
].
length
===
1
)
dayOfTheMonth
[
i
]
=
`0
${
dayOfTheMonth
[
i
]}
`
;
for
(
let
i
=
0
;
i
<
2
;
i
+=
1
)
if
(
dayOfTheMonth
[
i
].
length
===
1
)
dayOfTheMonth
[
i
]
=
`0
${
dayOfTheMonth
[
i
]}
`
;
// Junta o array, separando por /
// Junta o array, separando por /
...
@@ -59,13 +60,26 @@ function RedeHorarioCard({ mentoria }) {
...
@@ -59,13 +60,26 @@ function RedeHorarioCard({ mentoria }) {
});
});
function
onConfirm
(
data
)
{
function
onConfirm
(
data
)
{
const
newMentoria
=
{
...
mentoriaSelect
};
const
token
=
sessionStorage
.
getItem
(
'
token
'
);
const
token
=
sessionStorage
.
getItem
(
'
token
'
);
const
headers
=
{
headers
:
{
Authorization
:
`Bearer
${
token
}
`
}
};
const
headers
=
{
headers
:
{
Authorization
:
`Bearer
${
token
}
`
}
};
console
.
log
(
mentoria
);
marcarMentoria
(
headers
,
{
idMentoria
:
mentoria
.
idMentoria
,
choice
:
data
})
marcarMentoria
(
headers
,
{
idMentoria
:
mentoria
.
idMentoria
,
choice
:
data
})
.
then
((
res
)
=>
(
.
then
((
res
)
=>
{
res
.
status
===
200
if
(
res
.
status
===
200
)
{
?
enqueue
(
'
Mentoria cadastrada com sucesso
'
,
'
success
'
)
newMentoria
.
dateTime
.
forEach
((
element
)
=>
{
:
console
.
log
(
'
Falha ao marcar mentoria. Código:
'
,
res
.
status
)))
if
(
element
.
dayOfTheMonth
===
data
.
date
&&
element
.
times
[
0
].
hour
===
data
.
hour
)
{
// eslint-disable-next-line no-param-reassign
element
.
times
[
0
].
flagBusy
=
true
;
}
});
setMentoriaSelect
(
newMentoria
);
localStorage
.
setItem
(
'
updatedMentoria
'
,
JSON
.
stringify
(
newMentoria
));
enqueue
(
'
Mentoria cadastrada com sucesso
'
,
'
success
'
);
}
})
.
catch
((
err
)
=>
{
.
catch
((
err
)
=>
{
enqueue
(
'
Erro ao marcar mentoria
'
);
enqueue
(
'
Erro ao marcar mentoria
'
);
console
.
error
(
err
);
console
.
error
(
err
);
...
@@ -77,10 +91,10 @@ function RedeHorarioCard({ mentoria }) {
...
@@ -77,10 +91,10 @@ function RedeHorarioCard({ mentoria }) {
<>
<>
<
RedeMarcarMentoria
<
RedeMarcarMentoria
opened
=
{
open
}
opened
=
{
open
}
image
=
{
`
${
urlFiles
}
/
${
mentoria
.
image
}
`
}
image
=
{
`
${
urlFiles
}
/
${
mentoria
Select
.
image
}
`
}
title
=
{
mentoria
.
title
}
title
=
{
mentoria
Select
.
title
}
userName
=
{
mentoria
.
mentorInfos
.
name
}
userName
=
{
mentoria
Select
.
mentorInfos
.
name
}
userImage
=
{
`
${
urlFiles
}
/
${
mentoria
.
mentorInfos
.
image
}
`
}
userImage
=
{
`
${
urlFiles
}
/
${
mentoria
Select
.
mentorInfos
.
image
}
`
}
date
=
{
dateInfo
}
date
=
{
dateInfo
}
hour
=
{
timeInfo
}
hour
=
{
timeInfo
}
onClose
=
{
()
=>
setOpen
(
false
)
}
onClose
=
{
()
=>
setOpen
(
false
)
}
...
...
src/pages/mentoria/Mentoria.jsx
View file @
27f48b4d
import
React
,
{
useState
}
from
'
react
'
;
import
React
,
{
useState
,
useEffect
}
from
'
react
'
;
import
{
Redirect
}
from
'
react-router
'
;
import
{
Redirect
}
from
'
react-router
'
;
import
Container
from
'
./StyledComponents
'
;
import
Container
from
'
./StyledComponents
'
;
import
Caminho
from
'
../mentorias/StyledComponents/Caminho
'
;
import
Caminho
from
'
../mentorias/StyledComponents/Caminho
'
;
...
@@ -13,16 +13,30 @@ import Legend from './StyledComponents/Legend';
...
@@ -13,16 +13,30 @@ import Legend from './StyledComponents/Legend';
import
HeaderCard
from
'
./StyledComponents/HeaderCard
'
;
import
HeaderCard
from
'
./StyledComponents/HeaderCard
'
;
import
RedeHorarioCard
from
'
../../components/RedeHorarioCard/RedeHorarioCard
'
;
import
RedeHorarioCard
from
'
../../components/RedeHorarioCard/RedeHorarioCard
'
;
import
RedeHorarioButton
from
'
../../components/RedeHorarioButton/RedeHorarioButton
'
;
import
RedeHorarioButton
from
'
../../components/RedeHorarioButton/RedeHorarioButton
'
;
import
{
buscarMentoria
}
from
'
../../services/mentoria
'
;
function
Mentoria
()
{
function
Mentoria
()
{
const
[
redirectTo
,
setRedirectTo
]
=
useState
(
''
);
const
[
redirectTo
,
setRedirectTo
]
=
useState
(
''
);
const
mentoria
=
JSON
.
parse
(
sessionStorage
.
getItem
(
'
mentoriaSelected
'
)
);
const
[
mentoria
,
setMentoria
]
=
useState
(
null
);
const
areaConhecimento
=
sessionStorage
.
getItem
(
'
areaSelected
'
);
const
areaConhecimento
=
sessionStorage
.
getItem
(
'
areaSelected
'
);
// Http.put(`/mentoria/choice/${mentoria.idMentoria}`, data, headers);
useEffect
(()
=>
{
async
function
fetchMentoria
()
{
const
token
=
sessionStorage
.
getItem
(
'
token
'
);
const
{
idMentoria
}
=
JSON
.
parse
(
sessionStorage
.
getItem
(
'
mentoriaSelected
'
));
await
buscarMentoria
({
headers
:
{
Authorization
:
`Bearer
${
token
}
`
,
id
:
idMentoria
}
}).
then
(
(
res
)
=>
{
const
helpObj
=
res
.
data
;
helpObj
.
idMentoria
=
res
.
data
.
id
;
setMentoria
(
helpObj
);
},
).
catch
(()
=>
null
);
}
fetchMentoria
();
},
[]);
console
.
log
(
mentoria
);
console
.
log
(
mentoria
);
return
(
redirectTo
)
?
<
Redirect
to
=
{
redirectTo
}
/>
:
(
if
(
!
mentoria
)
return
null
;
return
(
redirectTo
)
?
(<
Redirect
to
=
{
redirectTo
}
/>)
:
(
<
Container
>
<
Container
>
<
CaminhoAp
>
<
CaminhoAp
>
<
CaminhoTitleDesabilitado
onClick
=
{
()
=>
setRedirectTo
(
'
/mentorado
'
)
}
>
Home
</
CaminhoTitleDesabilitado
>
<
CaminhoTitleDesabilitado
onClick
=
{
()
=>
setRedirectTo
(
'
/mentorado
'
)
}
>
Home
</
CaminhoTitleDesabilitado
>
...
...
src/services/mentoria.js
View file @
27f48b4d
...
@@ -5,4 +5,5 @@ export const atualizarMentoria = (headers, data) => Http.put(`/mentoria/alter/${
...
@@ -5,4 +5,5 @@ export const atualizarMentoria = (headers, data) => Http.put(`/mentoria/alter/${
export
const
marcarMentoria
=
(
headers
,
data
)
=>
Http
.
put
(
`/mentoria/choice/
${
data
.
idMentoria
}
`
,
data
.
choice
,
headers
);
export
const
marcarMentoria
=
(
headers
,
data
)
=>
Http
.
put
(
`/mentoria/choice/
${
data
.
idMentoria
}
`
,
data
.
choice
,
headers
);
export
const
mentoriasByMentor
=
(
headers
)
=>
Http
.
get
(
'
/mentoriaSession
'
,
headers
);
export
const
mentoriasByMentor
=
(
headers
)
=>
Http
.
get
(
'
/mentoriaSession
'
,
headers
);
export
const
cadastrarMentoria
=
(
headers
,
data
)
=>
Http
.
post
(
'
/cadastroMentoria
'
,
data
,
headers
);
export
const
cadastrarMentoria
=
(
headers
,
data
)
=>
Http
.
post
(
'
/cadastroMentoria
'
,
data
,
headers
);
export
const
mudarVisibilidade
=
(
headers
)
=>
Http
.
put
(
'
/mentoria/changeVisibility/
'
,
null
,
headers
);
export
const
mudarVisibilidade
=
(
headers
)
=>
Http
.
put
(
'
/mentoria/changeVisibility/
'
,
null
,
headers
);
\ No newline at end of file
export
const
buscarMentoria
=
(
headers
)
=>
Http
.
get
(
`/mentoria/
${
headers
.
headers
.
id
}
`
,
headers
);
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment