diff --git a/src/components/transactions/InputTransaction.tsx b/src/components/transactions/InputTransaction.tsx index 2bba97f..9f38939 100644 --- a/src/components/transactions/InputTransaction.tsx +++ b/src/components/transactions/InputTransaction.tsx @@ -14,6 +14,9 @@ export function InputTransaction({ show, closeModal }: { show: boolean, closeMod const [notes, setNotes] = useState(""); const [address, setAddress] = useState(""); + const [date, setDate] = useState(""); + const [time, setTime] = useState(""); + const [error, setError] = useState(""); const [successMsg, setSuccessMsg] = useState(""); @@ -24,12 +27,14 @@ export function InputTransaction({ show, closeModal }: { show: boolean, closeMod setSuccessMsg(null); if (!auth.currentUser) return setError("You are not signed in"); - - const date = new Date(); - const transaction = new Transaction() - .setDate(formatDate(date)) - .setTime(formatTime(date)) + let curTime = time; + if (date.trim() !== "" && curTime.trim() === "") curTime = "00:00:00" + else if (curTime.trim() === "") curTime = formatTime(new Date()) + + const transaction = new Transaction() + .setDate(date.trim() === "" ? formatDate(new Date()) : date) + .setTime(curTime) .setName(name) .setEmoji(category ? emojis[category] : undefined) .setCategory(category) @@ -55,6 +60,8 @@ export function InputTransaction({ show, closeModal }: { show: boolean, closeMod setDescription(""); setNotes(""); setAddress(""); + setDate(""); + setTime(""); setAdded(true); } @@ -71,6 +78,9 @@ export function InputTransaction({ show, closeModal }: { show: boolean, closeMod {Object.entries(emojis).map(([category, emoji], i) => )} + setDate(e.target.value)} /> + setTime(e.target.value)} /> + setDescription(e.target.value)} /> setNotes(e.target.value)} /> setAddress(e.target.value)} /> diff --git a/src/components/transactions/Transaction.ts b/src/components/transactions/Transaction.ts index fa1311d..f5a5b1a 100644 --- a/src/components/transactions/Transaction.ts +++ b/src/components/transactions/Transaction.ts @@ -58,12 +58,12 @@ export class Transaction { setDate(date?: string) { const [day, month, year] = (date || "").split("/").map((n) => Number(n)); - - if (isNaN(day) || isNaN(month) || isNaN(year) || day < 1 || day > 31 || month < 1 || month > 12) { + + this.date = `${year}-${month}-${day}`; + + if (isNaN(Date.parse(this.date)) || isNaN(day) || isNaN(month) || isNaN(year) || day < 1 || day > 31 || month < 1 || month > 12) { this.isValid = false; this.invalidField = "date"; - } else { - this.date = `${year}-${month}-${day}`; } return this;