"ne changes "

new_001
sonali 2024-10-07 16:52:10 +05:30
parent 0dbced87d1
commit e259fabdaa
16 changed files with 352 additions and 108 deletions

View File

@ -33,7 +33,7 @@ function App() {
<Route path="/successPage" element={<IncomeSuccessfully />} /> <Route path="/successPage" element={<IncomeSuccessfully />} />
<Route path="/records" element={<Records />} /> <Route path="/records" element={<Records />} />
<Route element={<Layout />}> <Route element={<Layout />}>
<Route path="/income" element={<IncomePage />} /> {/* <Route path="/income" element={<IncomePage />} /> */}
<Route path="/amount" element={<AmountPage />} /> <Route path="/amount" element={<AmountPage />} />
<Route path="/category" element={<Category />} /> <Route path="/category" element={<Category />} />
</Route> </Route>
@ -46,7 +46,7 @@ function App() {
<Route path="/expense-records" element={<ExpenseRecords/>}/> <Route path="/expense-records" element={<ExpenseRecords/>}/>
<Route path="/expense-successfully" element={<ExpenseSuccessfully/>}/> <Route path="/expense-successfully" element={<ExpenseSuccessfully/>}/>
<Route element={<ExpenseLayout />}> <Route element={<ExpenseLayout />}>
<Route path="/expense" element={<ExpensePage/>}/> {/* <Route path="/expense" element={<ExpensePage/>}/> */}
<Route path="/expenseAmount" element={<ExpenseAmount/>}/> <Route path="/expenseAmount" element={<ExpenseAmount/>}/>
<Route path="/expenseCategory" element={<ExpenseCategory/>}/> <Route path="/expenseCategory" element={<ExpenseCategory/>}/>
</Route> </Route>

View File

@ -110,6 +110,22 @@
align-items: center; align-items: center;
margin-right: 10px; margin-right: 10px;
} }
@media (max-width: 375px) {
.backIcon {
position: absolute;
top: 13px;
margin: 35px;
left: 10px;
}
.arrow-icon {
font-size: 18px;
cursor: pointer;
}
}
@media (max-width: 768px) { @media (max-width: 768px) {
.edit-titles h1 { .edit-titles h1 {

View File

@ -95,7 +95,21 @@
.success-date-time{ .success-date-time{
color: #fff; color: #fff;
} }
@media (max-width: 375px) {
.arrows {
position: absolute;
top: 13px;
margin: 35px;
left: 10px;
}
.arrow-icon-1 {
font-size: 18px;
cursor: pointer;
}
}
@media (max-width: 768px) { @media (max-width: 768px) {
.success-message h2 { .success-message h2 {

View File

@ -18,14 +18,12 @@
} }
.arrowbtn { .arrowbtn {
position: absolute; position: absolute;
left: 0; left: 0;
top: 50%; top: 50%;
margin: 20px 10px; margin: 20px 10px;
font-size: 4vw; /* Responsive font-size */ font-size: 4vw;
color: #333; color: #333;
cursor: pointer; cursor: pointer;
} }
@ -53,6 +51,7 @@
border-radius: 24px; border-radius: 24px;
padding: 10px; padding: 10px;
border-radius: 8px; border-radius: 8px;
/* margin: 10px; */
margin-bottom: 20px; margin-bottom: 20px;
} }
@ -69,13 +68,13 @@
height: 30px; height: 30px;
} }
.rupess_section { .rupess_section {
display: flex; display: flex;
justify-content: center; justify-content: center;
flex-wrap: wrap; flex-wrap: wrap;
gap: 15px; gap: 15px;
margin-top: 20px; margin: 10px;
margin-top: 50%;
} }
@ -102,10 +101,18 @@
} }
@media (max-width: 600px) { @media (max-width: 600px) {
.amount-container { .amount-container {
padding: 10px; padding: 10px;
max-width: 100%; max-width: 90%;
}
.amount-display{
width: 130px;
height: 20px;
} }
.backarrow { .backarrow {
@ -116,7 +123,7 @@
position: absolute; position: absolute;
/* left: 3%; */ /* left: 3%; */
top: 50%; top: 50%;
margin: 17px 30px; margin: 25px 30px;
/* transform: translateX(-20%); */ /* transform: translateX(-20%); */
font-size: 18px; font-size: 18px;
color: #333; color: #333;
@ -128,9 +135,15 @@
} }
.rupess_section { .rupess_section {
gap: 20px; display: flex;
justify-content: center;
flex-wrap: wrap;
gap: 25px;
margin: 10px;
margin-top: 100%;
} }
.coin { .coin {
width: 50px; width: 50px;
height: 50px; height: 50px;
@ -139,12 +152,12 @@
} }
.coin-value { .coin-value {
font-size: 26px; font-size: 24px;
} }
.Rupeesicon { .Rupeesicon {
width: 33px; width: 25px;
height: 33px; height: 25px;
} }
.total-amount { .total-amount {
@ -155,7 +168,15 @@
.coin:hover { .coin:hover {
background-color: #4caf50; background-color: #4caf50;
} }
.btn-group{
justify-content: space-between;
margin-top: 20px;
position: relative;
display: flex;
direction: row;
gap: 25px;
}
} }
@media (min-width: 1024px) { @media (min-width: 1024px) {
@ -181,12 +202,22 @@
.Rupeesicon { .Rupeesicon {
width: 30px; width: 30px;
height: 30px; height: 30px;
padding: 10px; padding: 7px;
} }
.total-amount { .total-amount {
font-size: 40px; font-size: 40px;
} }
.btn-group{
justify-content: space-between;
margin-top: 20px;
position: relative;
display: flex;
direction: row;
gap: 25px;
}
} }
@media (max-width: 375px) { @media (max-width: 375px) {
@ -210,7 +241,7 @@
.rupess_section { .rupess_section {
gap: 20px; gap: 20px;
margin-top: 10px; margin-top: 90%;
} }
.coin { .coin {
@ -230,4 +261,15 @@
.total-amount { .total-amount {
font-size: 26px; font-size: 26px;
} }
.btn-group{
justify-content: space-between;
margin-top: 20px;
position: relative;
display: flex;
direction: row;
gap: 25px;
}
} }

View File

@ -1,5 +1,4 @@
import React, { useState } from "react";
import React from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faArrowLeft } from "@fortawesome/free-solid-svg-icons"; import { faArrowLeft } from "@fortawesome/free-solid-svg-icons";
import { useNavigate, useOutletContext, useLocation } from "react-router-dom"; import { useNavigate, useOutletContext, useLocation } from "react-router-dom";
@ -7,21 +6,34 @@ import rupeeIcon from "../../../../assets/Rupees.png";
import "../ExpenseAmount/ExpenseAmount.css"; import "../ExpenseAmount/ExpenseAmount.css";
function ExpenseAmount() { function ExpenseAmount() {
const navigate = useNavigate(); const navigate = useNavigate();
const location = useLocation(); const location = useLocation();
const { entryType } = location.state || {}; const { entryType } = location.state || {};
const [totalAmount, setTotalAmount] = useOutletContext(); const [totalAmount, setTotalAmount] = useOutletContext();
const [isClickable, setIsClickable] = useState(true);
const [lastAddedAmount, setLastAddedAmount] = useState(0);
const handleCoinClick = (amount) => { const handleCoinClick = (amount) => {
if (isClickable) {
setTotalAmount((prevAmount) => prevAmount + amount); setTotalAmount((prevAmount) => prevAmount + amount);
setLastAddedAmount(amount);
setIsClickable(false);
setTimeout(() => {
setIsClickable(true);
}, 500);
}
};
const handleSubtractClick = (amount) => {
if (totalAmount >= amount) { // Ensure you do not go negative
setTotalAmount((prevAmount) => prevAmount - amount);
}
}; };
const handleBackClick = () => { const handleBackClick = () => {
console.log(entryType); console.log(entryType);
navigate("/expense", { state: { entryType } }); navigate("/", { state: { entryType } });
}; };
return ( return (
@ -35,34 +47,41 @@ function ExpenseAmount() {
/> />
</div> </div>
<div className="amount-display"> <div className="amount-display">
<h3 className="amount-titles">Amount</h3> <h3 className="amount-titles">Amount</h3>
<img src={rupeeIcon} alt="Rupee Icon" className="Rupeesicon" /> <img src={rupeeIcon} alt="Rupee Icon" className="Rupeesicon" />
</div> </div>
<section className="rupess_section"> <section className="rupess_section">
<div className="coin" onClick={() => handleCoinClick(50)}> <div className={`coin ${!isClickable ? "disabled" : ""}`} onClick={() => handleCoinClick(50)}>
<div className="coin-value">50</div> <div className="coin-value">50</div>
</div> </div>
<div className="coin" onClick={() => handleCoinClick(100)}> <div className={`coin ${!isClickable ? "disabled" : ""}`} onClick={() => handleCoinClick(100)}>
<div className="coin-value">100</div> <div className="coin-value">100</div>
</div> </div>
<div className="coin" onClick={() => handleCoinClick(200)}> <div className={`coin ${!isClickable ? "disabled" : ""}`} onClick={() => handleCoinClick(200)}>
<div className="coin-value">200</div> <div className="coin-value">200</div>
</div> </div>
<div className="coin" onClick={() => handleCoinClick(500)}> <div className={`coin ${!isClickable ? "disabled" : ""}`} onClick={() => handleCoinClick(500)}>
<div className="coin-value">500</div> <div className="coin-value">500</div>
</div> </div>
<div className="coin" onClick={() => handleCoinClick(1000)}> <div className={`coin ${!isClickable ? "disabled" : ""}`} onClick={() => handleCoinClick(1000)}>
<div className="coin-value">1000</div> <div className="coin-value">1000</div>
</div> </div>
</section> </section>
<div className="btn-group">
<button onClick={() => handleSubtractClick(lastAddedAmount)} disabled={lastAddedAmount === 0}>
-
</button>
<button onClick={() => handleCoinClick(lastAddedAmount)}>
+
</button>
</div>
</div> </div>
); );
} }

View File

@ -11,14 +11,15 @@ body {
width: 80%; width: 80%;
max-width: 500px; max-width: 500px;
height: 340px; height: 340px;
top: 50%; top: 32%;
left: 50%; left: 50%;
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
color: white; color: white;
font-family: 'Montserrat', sans-serif; font-family: 'Montserrat', sans-serif;
background: #1e1e1e; background: #1e1e1e;
box-shadow: -8px -8px 12px rgba(50, 50, 51, 0.66), 8px 8px 16px #040404, box-shadow: -8px -8px 12px rgba(50, 50, 51, 0.66), 8px 8px 16px #040404,
inset -2px -2px 2px rgba(255, 255, 255, 0.64), inset -2px -2px 2px rgba(50, 50, 51, 0.66),
inset 2px 2px 2px rgba(39, 39, 44, 0.56); inset 2px 2px 2px rgba(39, 39, 44, 0.56);
padding: 8px; padding: 8px;
box-sizing: border-box; box-sizing: border-box;
@ -88,8 +89,9 @@ body {
@media (max-width: 768px) { @media (max-width: 768px) {
.total-amount-container { .total-amount-container {
width: 90%; width: 80%;
top: 65%; height: 45%;
top: 35%;
} }
.input-group { .input-group {
@ -103,21 +105,24 @@ body {
} }
.button-group { .button-group {
flex-direction: column; flex-direction: row;
align-items: center; align-items: center;
gap: 15px;
} }
.add-entry-1, .add-entry-1,
.add-entry-2 { .add-entry-2 {
width: 100%; width: 50%;
margin: 10px 0; margin: 5px 0;
} }
} }
@media (max-width: 480px) { @media (max-width: 480px) {
.total-amount-container { .total-amount-container {
/* padding: 15px; */ /* padding: 15px; */
margin: 20px 0px 0px 0px ; top: 35%;
margin: 0px 0px 0px 0px ;
height: auto;
} }
.add-entry-1, .add-entry-1,

View File

@ -26,13 +26,12 @@ function TotalExpenseAmount({ totalAmount, category, setCategory }) {
const handleAddEntry = () => { const handleAddEntry = () => {
setCategoryError(''); setCategoryError('');
// Ensure amount is a number and greater than zero
if (amount <= 0) { if (amount <= 0) {
alert('Amount is required and must be greater than zero'); alert('Amount is required and must be greater than zero');
return null; return null;
} }
if (!category) { if (!category) {
setCategoryError('Category is required'); setCategoryError('Category is required');
return null; return null;
@ -41,7 +40,6 @@ function TotalExpenseAmount({ totalAmount, category, setCategory }) {
const now = new Date(); const now = new Date();
const formattedDateTime = now.toLocaleString(); const formattedDateTime = now.toLocaleString();
const newEntry = { const newEntry = {
id: Date.now(), id: Date.now(),
amount: parseFloat(amount), amount: parseFloat(amount),
@ -49,8 +47,6 @@ function TotalExpenseAmount({ totalAmount, category, setCategory }) {
dateTime: formattedDateTime, dateTime: formattedDateTime,
type: entryType type: entryType
}; };
console.log(entryType)
if (!categories.includes(category)) { if (!categories.includes(category)) {
setCategories([...categories, category]); setCategories([...categories, category]);
@ -58,7 +54,6 @@ function TotalExpenseAmount({ totalAmount, category, setCategory }) {
const updatedEntries = [...entries, newEntry]; const updatedEntries = [...entries, newEntry];
if (updatedEntries.length > 5) { if (updatedEntries.length > 5) {
updatedEntries.shift(); updatedEntries.shift();
} }
@ -66,7 +61,6 @@ function TotalExpenseAmount({ totalAmount, category, setCategory }) {
setEntries(updatedEntries); setEntries(updatedEntries);
localStorage.setItem('entries', JSON.stringify(updatedEntries)); localStorage.setItem('entries', JSON.stringify(updatedEntries));
setCategory(''); setCategory('');
setAmount(''); setAmount('');
@ -83,28 +77,62 @@ function TotalExpenseAmount({ totalAmount, category, setCategory }) {
const handleSaveAndAddEntry = () => { const handleSaveAndAddEntry = () => {
const timestamp = handleAddEntry(); const timestamp = handleAddEntry();
if (timestamp) { if (timestamp) {
navigate('/expense'); navigate('/');
} }
}; };
const handleCategoryFocus = () => {
navigate('/expenseCategory');
};
const handleAmountFocus = () => {
navigate('/expenseAmount');
};
const handleAmountMouseDown = (e) => {
e.preventDefault(); // Prevents the keyboard from opening
handleAmountFocus(); // Navigate on first click
};
const handleCategoryMouseDown = (e) => {
e.preventDefault(); // Prevents the keyboard from opening
handleCategoryFocus(); // Navigate on first click
};
const handleAmountDoubleClick = () => {
const input = document.getElementById("amount-input");
input.focus();
};
const handleCategoryDoubleClick = () => {
const input = document.getElementById("category-input");
input.focus();
};
return ( return (
<div className="total-amount-container"> <div className="total-amount-container">
<div className="input-group"> <div className="input-group">
<div className="amount-input"> <div className="amount-input">
<label>Total:</label> <label>Total:</label>
<input <input
id="amount-input"
type="number" type="number"
value={amount} value={amount}
onChange={(e) => setAmount(e.target.value)} onChange={(e) => setAmount(e.target.value)}
onMouseDown={handleAmountMouseDown}
onDoubleClick={handleAmountDoubleClick}
placeholder="Enter Amount" placeholder="Enter Amount"
/> />
</div> </div>
<div className="category-input"> <div className="category-input">
<label>Category:</label> <label>Category:</label>
<input <input
id="category-input"
type="text" type="text"
value={category} value={category}
onChange={(e) => setCategory(e.target.value)} onChange={(e) => setCategory(e.target.value)}
onMouseDown={handleCategoryMouseDown}
onDoubleClick={handleCategoryDoubleClick}
placeholder="Add Category" placeholder="Add Category"
/> />
{categoryError && <span className="error-message">{categoryError}</span>} {categoryError && <span className="error-message">{categoryError}</span>}
@ -118,7 +146,4 @@ function TotalExpenseAmount({ totalAmount, category, setCategory }) {
); );
} }
export default TotalExpenseAmount; export default TotalExpenseAmount;

View File

@ -70,7 +70,7 @@
flex-wrap: wrap; flex-wrap: wrap;
justify-content: center; justify-content: center;
width: 100%; width: 100%;
margin-top: 0px; margin-top: 20%;
} }
.cat-item { .cat-item {
@ -139,7 +139,9 @@ transition: border-color 0.3s ease, background-color 0.3s ease;
font-size: 20px; font-size: 20px;
} }
.arrow{
margin: 13px 10px;
}
.category01 { .category01 {
width: 35px; width: 35px;
@ -158,17 +160,28 @@ transition: border-color 0.3s ease, background-color 0.3s ease;
top: 40px; top: 40px;
left: 40px; left: 40px;
} }
.category-display{
width: 130px;
height: 20px;
}
.category-titles { .category-titles {
font-size: 18px; font-size: 15px;
color: #fff; color: #fff;
} }
.category-list {
display: flex;
flex-wrap: wrap;
justify-content: center;
width: 100%;
margin-top: 90%;
}
.category01 { .category01 {
width: 30px; width: 25px;
margin: 7px; margin: 5px;
height: 30px; height: 25px;
} }
.cat-item { .cat-item {
@ -186,6 +199,7 @@ transition: border-color 0.3s ease, background-color 0.3s ease;
@media (max-width: 375px) { @media (max-width: 375px) {
.category-container { .category-container {
padding: 0; padding: 0;
} }
.arrow-icon { .arrow-icon {
@ -201,11 +215,20 @@ transition: border-color 0.3s ease, background-color 0.3s ease;
.category-display { .category-display {
width: 120px; width: 120px;
height: 25px; height: 20px;
margin: 35px auto; margin: 30px auto;
font-size: 14px; font-size: 14px;
} }
.category-list {
display: flex;
flex-wrap: wrap;
justify-content: center;
width: 100%;
margin-top: 75%;
}
.category-titles { .category-titles {
font-size: 14px; font-size: 14px;
margin-right: 2px; margin-right: 2px;
@ -213,8 +236,8 @@ transition: border-color 0.3s ease, background-color 0.3s ease;
.category01 { .category01 {
width: 25px; width: 25px;
margin: 4px;
height: 25px; height: 25px;
margin: 5px;
} }
.cat-item { .cat-item {

View File

@ -19,7 +19,7 @@ function ExpenseCategory() {
const entryType = location.state?.entryType; const entryType = location.state?.entryType;
const handleBackClick = () => { const handleBackClick = () => {
navigate("/income", { state: { entryType } }); navigate("/", { state: { entryType } });
console.log(entryType); console.log(entryType);
} }

View File

@ -7,6 +7,7 @@
border-radius: 10px; border-radius: 10px;
/* box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); */ /* box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); */
text-align: center; text-align: center;
} }
.arrow-container { .arrow-container {
@ -48,9 +49,8 @@
.button-container { .button-container {
display: flex; display: flex;
justify-content: center; justify-content: center;
margin-top: 20px; margin-top: 100%;
} }
.amount-btn{ .amount-btn{
width: 37%; width: 37%;
@ -156,6 +156,7 @@
.category-btn { .category-btn {
font-size: 18px; font-size: 18px;
} }
} }

View File

@ -157,6 +157,20 @@
font-size: 14px; font-size: 14px;
} }
.back_arrows {
position: absolute;
top: 13px;
margin: 35px;
left: 10px;
}
.arrow-icon {
font-size: 18px;
margin: 9px 0px 0px 0px;
cursor: pointer;
}
} }

View File

@ -5,7 +5,10 @@
justify-content: center; justify-content: center;
align-items: center; align-items: center;
height: 100vh; height: 100vh;
/* margin-bottom: 5px; */
overflow: hidden;
position: relative; position: relative;
font-family: 'Montserrat', sans-serif;
} }
.arrow { .arrow {
@ -15,7 +18,7 @@
.arr { .arr {
position: absolute; position: absolute;
top: 10px; top: 0px;
left: 0px; left: 0px;
} }
@ -102,7 +105,17 @@
font-size: 14px; font-size: 14px;
} }
.arrow {
font-size: 18px;
cursor: pointer;
position: absolute;
top: 8px;
margin: 35px;
left: 5px;
}
.arr { .arr {
position: absolute;
top: 0px; top: 0px;
left: 0px; left: 0px;
} }
@ -135,6 +148,18 @@
} }
} }
@media (max-width: 375px) {
.arrow {
font-size: 18px;
cursor: pointer;
}
.arr {
position: absolute;
top: 0px;
left: 0px;
}
}
/* Large screens (1025px and up) */ /* Large screens (1025px and up) */
@media (min-width: 1025px) { @media (min-width: 1025px) {
.btn1, .bt_11 { .btn1, .bt_11 {
@ -142,7 +167,10 @@
height: 50px; height: 50px;
font-size: 18px; font-size: 18px;
} }
.arr {
top: 0px;
left: 0px;
}
.payment-title h1 { .payment-title h1 {
font-size: 30px; font-size: 30px;
} }

View File

@ -1,4 +1,4 @@
import React from "react"; import React, {useState} from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faArrowLeft } from "@fortawesome/free-solid-svg-icons"; import { faArrowLeft } from "@fortawesome/free-solid-svg-icons";
import { useNavigate, useLocation , useOutletContext} from "react-router-dom"; import { useNavigate, useLocation , useOutletContext} from "react-router-dom";
@ -9,16 +9,31 @@ function AmountPage() {
const navigate = useNavigate(); const navigate = useNavigate();
const location = useLocation(); const location = useLocation();
const { entryType } = location.state || {}; const { entryType } = location.state || {};
const [totalAmount, setTotalAmount] = useOutletContext(); const [totalAmount, setTotalAmount] = useOutletContext();
const [isClickable, setIsClickable] = useState(true);
const [lastAddedAmount, setLastAddedAmount] = useState(0);
const handleCoinClick = (amount) => { const handleCoinClick = (amount) => {
if (isClickable) {
setTotalAmount((prevAmount) => prevAmount + amount); setTotalAmount((prevAmount) => prevAmount + amount);
setLastAddedAmount(amount);
setIsClickable(false);
setTimeout(() => {
setIsClickable(true);
}, 500);
}
};
const handleSubtractClick = (amount) => {
if (totalAmount >= amount) { // Ensure you do not go negative
setTotalAmount((prevAmount) => prevAmount - amount);
}
}; };
const handleBackClick = () => { const handleBackClick = () => {
console.log(entryType); console.log(entryType);
navigate("/income", { state: { entryType } }); navigate("/", { state: { entryType } });
}; };
return ( return (
@ -38,22 +53,35 @@ function AmountPage() {
</div> </div>
<section className="rupess_section"> <section className="rupess_section">
<div className="coin" onClick={() => handleCoinClick(50)}> <div className={`coin ${!isClickable ? "disabled" : ""}`} onClick={() => handleCoinClick(50)}>
<div className="coin-value">50</div> <div className="coin-value">50</div>
</div> </div>
<div className="coin" onClick={() => handleCoinClick(100)}>
<div className={`coin ${!isClickable ? "disabled" : ""}`} onClick={() => handleCoinClick(100)}>
<div className="coin-value">100</div> <div className="coin-value">100</div>
</div> </div>
<div className="coin" onClick={() => handleCoinClick(200)}>
<div className={`coin ${!isClickable ? "disabled" : ""}`} onClick={() => handleCoinClick(200)}>
<div className="coin-value">200</div> <div className="coin-value">200</div>
</div> </div>
<div className="coin" onClick={() => handleCoinClick(500)}>
<div className={`coin ${!isClickable ? "disabled" : ""}`} onClick={() => handleCoinClick(500)}>
<div className="coin-value">500</div> <div className="coin-value">500</div>
</div> </div>
<div className="coin" onClick={() => handleCoinClick(1000)}>
<div className={`coin ${!isClickable ? "disabled" : ""}`} onClick={() => handleCoinClick(1000)}>
<div className="coin-value">1000</div> <div className="coin-value">1000</div>
</div> </div>
</section> </section>
<div className="btn-group">
<button onClick={() => handleSubtractClick(lastAddedAmount)} disabled={lastAddedAmount === 0}>
-
</button>
<button onClick={() => handleCoinClick(lastAddedAmount)}>
+
</button>
</div>
</div> </div>
); );
} }

View File

@ -26,13 +26,12 @@ function TotalAmount({ totalAmount, category, setCategory }) {
const handleAddEntry = () => { const handleAddEntry = () => {
setCategoryError(''); setCategoryError('');
// Ensure amount is a number and greater than zero
if (amount <= 0) { if (amount <= 0) {
alert('Amount is required and must be greater than zero'); alert('Amount is required and must be greater than zero');
return null; return null;
} }
if (!category) { if (!category) {
setCategoryError('Category is required'); setCategoryError('Category is required');
return null; return null;
@ -41,7 +40,6 @@ function TotalAmount({ totalAmount, category, setCategory }) {
const now = new Date(); const now = new Date();
const formattedDateTime = now.toLocaleString(); const formattedDateTime = now.toLocaleString();
const newEntry = { const newEntry = {
id: Date.now(), id: Date.now(),
amount: parseFloat(amount), amount: parseFloat(amount),
@ -49,8 +47,6 @@ function TotalAmount({ totalAmount, category, setCategory }) {
dateTime: formattedDateTime, dateTime: formattedDateTime,
type: entryType type: entryType
}; };
console.log(entryType)
if (!categories.includes(category)) { if (!categories.includes(category)) {
setCategories([...categories, category]); setCategories([...categories, category]);
@ -65,7 +61,6 @@ function TotalAmount({ totalAmount, category, setCategory }) {
setEntries(updatedEntries); setEntries(updatedEntries);
localStorage.setItem('entries', JSON.stringify(updatedEntries)); localStorage.setItem('entries', JSON.stringify(updatedEntries));
// Reset input fields
setCategory(''); setCategory('');
setAmount(''); setAmount('');
@ -82,28 +77,62 @@ function TotalAmount({ totalAmount, category, setCategory }) {
const handleSaveAndAddEntry = () => { const handleSaveAndAddEntry = () => {
const timestamp = handleAddEntry(); const timestamp = handleAddEntry();
if (timestamp) { if (timestamp) {
navigate('/income'); navigate('/');
} }
}; };
const handleCategoryFocus = () => {
navigate('/category');
};
const handleAmountFocus = () => {
navigate('/amount');
};
const handleAmountMouseDown = (e) => {
e.preventDefault(); // Prevents the keyboard from opening
handleAmountFocus(); // Navigate on first click
};
const handleCategoryMouseDown = (e) => {
e.preventDefault(); // Prevents the keyboard from opening
handleCategoryFocus(); // Navigate on first click
};
const handleAmountDoubleClick = () => {
const input = document.getElementById("amount-input");
input.focus();
};
const handleCategoryDoubleClick = () => {
const input = document.getElementById("category-input");
input.focus();
};
return ( return (
<div className="total-amount-container"> <div className="total-amount-container">
<div className="input-group"> <div className="input-group">
<div className="amount-input"> <div className="amount-input">
<label>Total:</label> <label>Total:</label>
<input <input
id="amount-input"
type="number" type="number"
value={amount} value={amount}
onChange={(e) => setAmount(e.target.value)} onChange={(e) => setAmount(e.target.value)}
onMouseDown={handleAmountMouseDown}
onDoubleClick={handleAmountDoubleClick}
placeholder="Enter Amount" placeholder="Enter Amount"
/> />
</div> </div>
<div className="category-input"> <div className="category-input">
<label>Category:</label> <label>Category:</label>
<input <input
id="category-input"
type="text" type="text"
value={category} value={category}
onChange={(e) => setCategory(e.target.value)} onChange={(e) => setCategory(e.target.value)}
onMouseDown={handleCategoryMouseDown}
onDoubleClick={handleCategoryDoubleClick}
placeholder="Add Category" placeholder="Add Category"
/> />
{categoryError && <span className="error-message">{categoryError}</span>} {categoryError && <span className="error-message">{categoryError}</span>}

View File

@ -17,7 +17,7 @@ function Category() {
const entryType = location.state?.entryType; const entryType = location.state?.entryType;
const handleBackClick = () => { const handleBackClick = () => {
navigate("/income", { state: { entryType } }); navigate("/", { state: { entryType } });
console.log(entryType); console.log(entryType);
} }

View File

@ -20,13 +20,13 @@ function Home() {
const handleIncomeClick = () => { const handleIncomeClick = () => {
setEntryType('income'); setEntryType('income');
console.log(entryType) console.log(entryType)
navigate('/income', { state: { entryType: 'income' } }); navigate('/amount', { state: { entryType: 'income' } });
}; };
const handleExpenseClick = () => { const handleExpenseClick = () => {
setEntryType('expense'); setEntryType('expense');
console.log(entryType) console.log(entryType)
navigate('/expense', { state: { entryType: 'expense' } }); navigate('/expenseAmount', { state: { entryType: 'expense' } });
} }
return ( return (