@ -7,8 +7,6 @@ import { MaterialCommunityIcons } from "@expo/vector-icons";
import { AuthContext } from "../auth/context" ;
import authStorage from "../auth/storage" ;
import {
Form ,
SubmitButton ,
@ -17,7 +15,7 @@ import {
} from "../components/forms" ;
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view" ;
import ConfirmationModal from "../components/ConfirmationModal" ;
import { userPersonalData } from "../api/auth" ;
import { userActivation } from "../api/auth" ;
function Header ( ) {
return (
@ -43,20 +41,27 @@ function Header() {
}
function Institution ( { user , institutionRole } ) {
var institutionMap = {
const institutionMap = {
E : "Escola" ,
D : "Defesa Civil" ,
N : "Não governamental" ,
O : "Outra" ,
N : "Nenhuma"
N : "Nenhuma" ,
} ;
const roleMap = {
ROLE_CLIENT : "Não responsável" ,
ROLE_INSTITUTION : "Responsável" ,
}
return (
< View style = { { marginTop : 24 , marginBottom : 24 } } >
< Text style = { styles . label } > Tippo de instituição : < / T e x t >
< View style = { { flexDirection : "row" } } >
< MaterialCommunityIcons name = "bank" size = { 30 } color = { colors . primary } / >
< Text style = { styles . subText } > { institutionMap [ user . institutiontype ] } < / T e x t >
< Text style = { styles . subText } >
{ institutionMap [ user . institutiontype ] }
< / T e x t >
< / V i e w >
< Text style = { [ styles . label , { marginTop : 24 } ] } >
@ -76,19 +81,24 @@ function Institution({ user, institutionRole }) {
size = { 30 }
color = { colors . primary }
/ >
< Text style = { styles . subText } > { institutionRole } < / T e x t >
< Text style = { styles . subText } > { roleMap [ user . role ] } < / T e x t >
< / V i e w >
< / V i e w >
) ;
}
function ValidateCode ( { institutionRole , user } ) {
// 950ebd56-7acc-4b45-9366-23a0f814f3f2
// 1199990987
function ValidateCode ( { user } ) {
return (
< View flex = { 1 } padding = { 16 } width = "100%" >
< Header / >
< Institution user = { user } institutionRole = { institutionRole } / >
< Institution user = { user } / >
< Text style = { [ styles . label ] } > Código de ativação : < / T e x t >
< View style = { styles . iconField } >
< MaterialCommunityIcons
name = "key"
@ -101,7 +111,7 @@ function ValidateCode({ institutionRole, user }) {
< FormField
paddingRight = { 2 }
flex = { 1 }
maxLength = { 12 }
maxLength = { 36 }
name = "code"
numberOfLines = { 2 }
placeholder = "Digite o código de ativação"
@ -113,33 +123,36 @@ function ValidateCode({ institutionRole, user }) {
) ;
}
function verifyCode ( code ) {
return true ;
}
function processOnSubmit ( navigation , form , instRole , setShowLog ) {
if ( instRole == "Não responsável" ) {
if ( verifyCode ( form . code ) ) {
setShowLog ( { show : true , message : true } ) ;
} else {
setShowLog ( { show : true , message : false } ) ;
}
async function processOnSubmit ( navigation , form , instRole , setShowLog ) {
const response = await userActivation ( form . code ) ;
console . log ( "==============================================================================" )
console . log ( response )
} else if ( verifyCode ( form . code ) ) {
navigation . navigate ( "ActivateInstitutionShowCode" , { code : form . code } ) ;
if ( instRole == "Não responsável" ) {
if ( response . ok ) {
setShowLog ( { show : true , message : true } ) ;
} else {
setShowLog ( { show : true , message : false } ) ;
setShowLog ( { show : true , message : false } ) ;
}
} else if ( response . ok ) {
navigation . navigate ( "ActivateInstitutionShowCode" ) ;
} else {
setShowLog ( { show : true , message : false } ) ;
}
// navigation.navigate("ActivateInstitutionShowCode", { code: form.code });
// navigation.navigate("ActivateInstitutionShowCode", { code: form.code });
}
export default function ActivateInstitutionCode ( { route , navigation } ) {
const { instRole } = route . params ;
export default function ActivateInstitutionCode ( { navigation } ) {
const { user , _ } = useContext ( AuthContext ) ;
// FIXME: wpdAuth has errors while giving /me data for ROLE_INSTITUTION
user . role = "ROLE_CLIENT"
// console.log(user)
const initialState = { show : false , message : true }
const initialState = { show : false , message : true } ;
const [ showLog , setShowLog ] = useState ( initialState ) ;
return (
@ -149,19 +162,23 @@ export default function ActivateInstitutionCode({ route, navigation }) {
} }
onSubmit = { ( form ) => {
console . log ( "Forms values: \n" + JSON . stringify ( form ) ) ;
processOnSubmit ( navigation , form , instR ole, setShowLog ) ;
processOnSubmit ( navigation , form , user . r ole, setShowLog ) ;
} }
>
< ConfirmationModal
show = { showLog . show }
description = { showLog . message ? "O código de ativação foi validado com sucesso." : "O código de ativação informado não coincide com o código do responsável pela instituição no Cemaden Educação." }
description = {
showLog . message
? "O código de ativação foi validado com sucesso."
: "O código de ativação informado não coincide com o código do responsável pela instituição no Cemaden Educação."
}
confirmationLabel = "OK"
onConfirm = { ( ) => setShowLog ( initialState ) }
onDecline = { ( ) => setShowLog ( initialState ) }
/ >
< KeyboardAwareScrollView >
< ValidateCode user = { user } institutionRole = { instRole } / >
< ValidateCode user = { user } / >
< / K e y b o a r d A w a r e S c r o l l V i e w >
< / F o r m >
) ;