Fakultas Ilmu Komputer UI

Commit 62304374 authored by jahnsmichael's avatar jahnsmichael
Browse files

[GREEN] integrate fetching with markup

parent 6e1bd4b7
Pipeline #77355 passed with stage
in 24 minutes and 42 seconds
import { useNavigation } from "@react-navigation/native";
import { Box, Button, Cloud, Field, Gap, Text } from "components";
import styled from 'styled-components/native';
import React, { useState } from "react";
import React, { useContext, useState } from "react";
import { Image } from "react-native";
import WaveBackground from 'assets/arts/background-wave.png';
import WonderingIllustration from 'assets/illustrations/wondering.png';
import DoctorTeamIllustration from 'assets/illustrations/doctor-team.png';
import { useFormState } from "helpers";
import { AppContext } from "contexts";
enum ForgetPasswordResponse {
Success = 'Password berhasil diubah, silakan cek email anda.',
BadRequest = 'Terjadi kesalahan, periksa kembali email anda.',
UnknownServerError = 'Terjadi kesalahan pada server.',
NoInternetConn = 'Cek Konektivitas Internet',
}
const ForgetPasswordPage = () => {
const [isFirstTime, setIsFirstTime] = useState(true);
const { services, setAlert, shouldLoading, setShouldLoading } = useContext(AppContext);
const [form, setField] = useFormState({
email: {
type: 'EMAIL'
......@@ -59,10 +71,45 @@ const ForgetPasswordPage = () => {
<Button
id="submit"
type={Button.Type.Filled}
clickable={!shouldLoading}
onPress={async () => {
if (isFirstTime) {
setIsFirstTime(false);
}
if (form.isValid) {
setShouldLoading(true)
const forgetPassRes = await services.main.forgetPassword({
email: form.fields.email.value,
})
setShouldLoading(false)
if (forgetPassRes === undefined) {
setAlert({
illustration: WonderingIllustration,
message: ForgetPasswordResponse.NoInternetConn,
})
} else {
if (forgetPassRes.status === 200) {
setAlert({
illustration: DoctorTeamIllustration,
message: ForgetPasswordResponse.Success,
})
} else if (forgetPassRes.status === 400) {
setAlert({
illustration: WonderingIllustration,
message: ForgetPasswordResponse.BadRequest,
})
} else {
setAlert({
illustration: WonderingIllustration,
message: ForgetPasswordResponse.UnknownServerError,
})
}
}
}
}}
>Kirim Email Verifikasi</Button>
</Box>
......
Supports Markdown
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