update
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
import { useState, useContext, useCallback, MouseEvent } from 'react';
|
||||
import { AccountUserProfileContext } from '../hooks';
|
||||
import { toast } from 'sonner';
|
||||
import { getAuth,useAuthContext } from '@/auth';
|
||||
import { KeenIcon } from '@/components';
|
||||
|
||||
type PasswordType = 'current' | 'new' | 'retype';
|
||||
@ -12,7 +11,7 @@ const PinCode = () => {
|
||||
const [currentPincode, setCurrentPincode] = useState('');
|
||||
const [newPincode, setNewPincode] = useState('');
|
||||
const [retypePincode, setRetypePincode] = useState('');
|
||||
const [errorRetype, setErrorRetype] = useState('');
|
||||
const [errorRetype, setErrorRetype] = useState('');
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [showPassword, setShowPassword] = useState({
|
||||
current: false,
|
||||
@ -20,6 +19,11 @@ const PinCode = () => {
|
||||
retype: false,
|
||||
});
|
||||
|
||||
// Fungsi hanya angka, maksimal 6 digit
|
||||
const handleNumericInput = (value: string) => {
|
||||
return value.replace(/\D/g, '').slice(0, 100);
|
||||
};
|
||||
|
||||
const handleResetPassword = useCallback(async () => {
|
||||
if (newPincode !== retypePincode) {
|
||||
toast.error('New Pin Code and Retype Pin Code do not match.');
|
||||
@ -39,7 +43,7 @@ const PinCode = () => {
|
||||
setCurrentPincode('');
|
||||
setNewPincode('');
|
||||
setRetypePincode('');
|
||||
setErrorRetype(''); // Clear error after success
|
||||
setErrorRetype('');
|
||||
} catch (error: any) {
|
||||
const errorMessage =
|
||||
error?.response?.data?.message ||
|
||||
@ -62,8 +66,9 @@ const PinCode = () => {
|
||||
);
|
||||
|
||||
const handleRetypeChange = (value: string) => {
|
||||
setRetypePincode(value);
|
||||
if (newPincode && value && newPincode !== value) {
|
||||
const numericValue = handleNumericInput(value);
|
||||
setRetypePincode(numericValue);
|
||||
if (newPincode && numericValue && newPincode !== numericValue) {
|
||||
setErrorRetype('New Pin Code and Retype Pin Code do not match.');
|
||||
} else {
|
||||
setErrorRetype('');
|
||||
@ -84,7 +89,7 @@ const PinCode = () => {
|
||||
className="form-control pr-10"
|
||||
placeholder="Current Pin Code"
|
||||
value={currentPincode}
|
||||
onChange={(e) => setCurrentPincode(e.target.value)}
|
||||
onChange={(e) => setCurrentPincode(handleNumericInput(e.target.value))}
|
||||
disabled={isSubmitting}
|
||||
type={showPassword.current ? 'text' : 'password'}
|
||||
/>
|
||||
@ -110,14 +115,10 @@ const PinCode = () => {
|
||||
placeholder="New Pin Code"
|
||||
value={newPincode}
|
||||
onChange={(e) => {
|
||||
setNewPincode(e.target.value);
|
||||
// Kalau retype sudah diisi, cek lagi error
|
||||
const value = handleNumericInput(e.target.value);
|
||||
setNewPincode(value);
|
||||
if (retypePincode) {
|
||||
if (e.target.value !== retypePincode) {
|
||||
setErrorRetype('New Pin Code and Retype Pin Code do not match.');
|
||||
} else {
|
||||
setErrorRetype('');
|
||||
}
|
||||
setErrorRetype(value !== retypePincode ? 'New Pin Code and Retype Pin Code do not match.' : '');
|
||||
}
|
||||
}}
|
||||
disabled={isSubmitting}
|
||||
|
||||
@ -267,7 +267,7 @@ const DashboardHomePage = () => {
|
||||
<Card
|
||||
title="Total Cash-in"
|
||||
total={responseStatisticCard?.data.total_cash_in ?? 0}
|
||||
growth={parseFloat((responseStatisticCard?.data?.cash_in_last_week.percent ?? 0).toFixed(2))?? 0}
|
||||
growth={parseFloat((responseStatisticCard?.data?.cash_in_last_week.percent ?? 0).toFixed(2)) ?? 0}
|
||||
surplus={responseStatisticCard?.data.cash_in_last_week.surplus ?? false}
|
||||
icon="test"
|
||||
/>
|
||||
@ -302,7 +302,14 @@ const DashboardHomePage = () => {
|
||||
type="date"
|
||||
name="from"
|
||||
value={moment(fromDate).format('YYYY-MM-DD')}
|
||||
onChange={(e) => setFromDate(new Date(e.target.value))}
|
||||
onChange={(e) => {
|
||||
if (e.target.value) {
|
||||
setFromDate(new Date(e.target.value));
|
||||
} else {
|
||||
// Reset to default value (e.g. first day of current month)
|
||||
setFromDate(getFirstDayOfMonth());
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
|
||||
@ -312,7 +319,14 @@ const DashboardHomePage = () => {
|
||||
type="date"
|
||||
name="to"
|
||||
value={moment(toDate).format('YYYY-MM-DD')}
|
||||
onChange={(e) => setToDate(new Date(e.target.value))}
|
||||
onChange={(e) => {
|
||||
if (e.target.value) {
|
||||
setToDate(new Date(e.target.value));
|
||||
} else {
|
||||
// Reset to default value (e.g. today)
|
||||
setToDate(getToday());
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user