Add counter logic to Account Verification screen

This commit is contained in:
Salwa Aisyah
2025-04-27 19:52:00 +07:00
parent a077d93029
commit 081a637463
2 changed files with 33 additions and 2 deletions

View File

@ -25,8 +25,19 @@ function AccountVerificationScreen() {
const navigation = useNavigation<AccountVerificationScreenNavigationProp>(); const navigation = useNavigation<AccountVerificationScreenNavigationProp>();
const [otp, setOtp] = useState(Array(6).fill('')); const [otp, setOtp] = useState(Array(6).fill(''));
const [counter, setCounter] = useState(10);
const inputRefs = useRef<TextInput[]>([]); const inputRefs = useRef<TextInput[]>([]);
useEffect(() => {
if (counter > 0) {
const timer = setTimeout(() => {
setCounter(counter - 1);
}, 1000);
return () => clearTimeout(timer);
}
}, [counter]);
const handleChange = (text: string, index: number) => { const handleChange = (text: string, index: number) => {
const newOtp = [...otp]; const newOtp = [...otp];
newOtp[index] = text; newOtp[index] = text;
@ -87,10 +98,22 @@ function AccountVerificationScreen() {
))} ))}
</View> </View>
<Text style={styles.OTPTimeText}> <Text style={styles.OTPTimeText}>
Kirim ulang kode OTP dalam 10 detik Kirim ulang kode OTP dalam <Text>{counter}</Text> detik
</Text> </Text>
</View> </View>
<Text style={styles.sendOTPText}>Kirim Ulang Kode OTP</Text> <Pressable
disabled={counter !== 0 ? true : false}
onPress={() => setCounter(10)}
style={({pressed}) => ({
transform: [{scale: pressed ? 0.95 : 1}],
})}>
<Text
style={
counter !== 0 ? styles.sendOTPTextDisabled : styles.sendOTPText
}>
Kirim Ulang Kode OTP
</Text>
</Pressable>
<Button <Button
mode="contained" mode="contained"
style={styles.accountVerificationButton} style={styles.accountVerificationButton}

View File

@ -46,6 +46,14 @@ const styles = StyleSheet.create({
...FontFamily.notoSansSemiBold, ...FontFamily.notoSansSemiBold,
fontSize: 12, fontSize: 12,
}, },
sendOTPTextDisabled: {
marginTop: 40,
marginHorizontal: 16,
textAlign: 'center',
color: Colors.neutral70.color,
...FontFamily.notoSansSemiBold,
fontSize: 12,
},
accountVerificationButton: { accountVerificationButton: {
marginHorizontal: 16, marginHorizontal: 16,
marginTop: 16, marginTop: 16,