" category disply in dropdown in home page (edit functionlity)"

new_001
sonali 2024-10-08 16:13:01 +05:30
parent b7be589ee7
commit cba9f8565a
2 changed files with 97 additions and 13 deletions

View File

@ -49,12 +49,69 @@
/* background-color: #333; */ /* background-color: #333; */
/* border: 1px solid #ddd; */ /* border: 1px solid #ddd; */
border-bottom: 1px solid #ddd; border-bottom: 1px solid #ddd;
color: #fff; color: #ffffff;
padding: 5px; padding: 5px;
border-radius: 5px; border-radius: 5px;
margin-right: 10px; margin-right: 10px;
flex: 1; flex: 1;
} }
.entries-list-container {
margin: 20px;
}
.entry-item {
display: flex;
align-items: center;
margin: 10px 0;
}
.entry-input {
margin-right: 10px;
padding: 5px;
}
.custom-dropdown {
position: relative;
display: inline-block;
margin-right: 10px;
}
.dropdown-button {
background-color: #f1f1f1;
color: #333;
padding: 1px;
font-size: 14px;
border: 1px solid #ccc;
cursor: pointer;
border-radius: 4px;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #1e1e1e;
font-size: 14px;
min-width: 10px;
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
z-index: 1;
margin-top: 1px;
border-radius: 4px;
}
.custom-dropdown:hover .dropdown-content {
display: block;
}
.dropdown-item {
padding: 8px 2px;
cursor: pointer;
}
.dropdown-item input {
margin-right: 8px;
}
/* Entry icons container */ /* Entry icons container */
.entry-icons { .entry-icons {

View File

@ -10,13 +10,19 @@ function EntriesList() {
const [entries, setEntries] = useState([]); const [entries, setEntries] = useState([]);
const [editingEntryId, setEditingEntryId] = useState(null); const [editingEntryId, setEditingEntryId] = useState(null);
const [editedAmount, setEditedAmount] = useState(""); const [editedAmount, setEditedAmount] = useState("");
const [editedCategory, setEditedCategory] = useState(""); const [selectedCategory, setSelectedCategory] = useState([]);
const [repeatEntry, setRepeatEntry] = useState(null); const [repeatEntry, setRepeatEntry] = useState(null);
const [isDialogOpen, setIsDialogOpen] = useState(false); const [isDialogOpen, setIsDialogOpen] = useState(false);
const [categories, setCategories] = useState(["Hair", "Clothing", "Food", "Books", "Electronics", "Other"]);
useEffect(() => { useEffect(() => {
const storedEntries = JSON.parse(localStorage.getItem("entries")) || []; const storedEntries = JSON.parse(localStorage.getItem("entries")) || [];
setEntries(storedEntries.slice(-5)); setEntries(storedEntries.slice(-5));
const storedCategories = JSON.parse(localStorage.getItem("categories")) || [];
const uniqueCategories = [...new Set([...categories, ...storedCategories])];
setCategories(uniqueCategories);
}, []); }, []);
const handleRedoClick = (entry) => { const handleRedoClick = (entry) => {
@ -27,12 +33,12 @@ function EntriesList() {
const handleEditClick = (entry) => { const handleEditClick = (entry) => {
setEditingEntryId(entry.id); setEditingEntryId(entry.id);
setEditedAmount(entry.amount); setEditedAmount(entry.amount);
setEditedCategory(entry.category); setSelectedCategory(entry.category || []); // Ensure selectedCategory is an array
}; };
const handleSaveClick = (entry) => { const handleSaveClick = (entry) => {
const updatedEntries = entries.map((e) => const updatedEntries = entries.map((e) =>
e.id === entry.id ? { ...e, amount: editedAmount, category: editedCategory } : e e.id === entry.id ? { ...e, amount: editedAmount, category: selectedCategory } : e
); );
setEntries(updatedEntries); setEntries(updatedEntries);
@ -50,7 +56,7 @@ function EntriesList() {
const newEntry = { const newEntry = {
id: new Date().getTime(), id: new Date().getTime(),
amount: repeatEntry.amount, amount: repeatEntry.amount,
category: repeatEntry.category, category: repeatEntry.category, // Ensure this is an array
type: repeatEntry.type, type: repeatEntry.type,
}; };
@ -58,7 +64,6 @@ function EntriesList() {
setEntries(updatedEntries); setEntries(updatedEntries);
localStorage.setItem("entries", JSON.stringify(updatedEntries)); localStorage.setItem("entries", JSON.stringify(updatedEntries));
// Navigate based on entry type
if (repeatEntry.type === "income") { if (repeatEntry.type === "income") {
navigate("/totalsuccessfully", { state: { entryId: newEntry.id } }); navigate("/totalsuccessfully", { state: { entryId: newEntry.id } });
} else { } else {
@ -70,6 +75,16 @@ function EntriesList() {
setRepeatEntry(null); setRepeatEntry(null);
}; };
const handleCategoryChange = (category) => {
setSelectedCategory(prevCategories => {
if (prevCategories.includes(category)) {
return prevCategories.filter(cat => cat !== category); // Remove category if already selected
} else {
return [...prevCategories, category]; // Add category if not selected
}
});
};
return ( return (
<div className="entries-list-container"> <div className="entries-list-container">
<h4>Previous Last Five Transactions:</h4> <h4>Previous Last Five Transactions:</h4>
@ -87,12 +102,22 @@ function EntriesList() {
onChange={(e) => setEditedAmount(e.target.value)} onChange={(e) => setEditedAmount(e.target.value)}
className="entry-input" className="entry-input"
/> />
<input <div className="custom-dropdown">
type="text" <button className="dropdown-button">
value={editedCategory} {selectedCategory.length > 0 ? selectedCategory.join(', ') : "Select Category"}
onChange={(e) => setEditedCategory(e.target.value)} </button>
className="entry-input" <div className="dropdown-content">
/> {categories.map((cat, idx) => (
<div
key={idx}
className="dropdown-item"
onClick={() => handleCategoryChange(cat)}
>
{cat}
</div>
))}
</div>
</div>
<FontAwesomeIcon <FontAwesomeIcon
icon={faSave} icon={faSave}
className="entry-save-icon" className="entry-save-icon"
@ -107,7 +132,9 @@ function EntriesList() {
) : ( ) : (
<> <>
<span className="entry-amount">{entry.amount}</span> <span className="entry-amount">{entry.amount}</span>
<span className="entry-category">{entry.category}</span> <span className="entry-category">
{entry.category.join(', ')} {/* Join array elements with a comma */}
</span>
<div className="entry-icons"> <div className="entry-icons">
<FontAwesomeIcon <FontAwesomeIcon
icon={faRedoAlt} icon={faRedoAlt}