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