From 8aaf2a0dea78f2df512a4c30d997bbadfc0af2dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=87?= Date: Tue, 6 Feb 2024 14:29:58 +0100 Subject: [PATCH] "Cancel" buttons replaced with --- app/ui/BillDeleteForm.tsx | 14 ++++++-------- app/ui/BillEditForm.tsx | 2 +- app/ui/LocationDeleteForm.tsx | 3 ++- app/ui/LocationEditForm.tsx | 26 ++++++++++---------------- 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/app/ui/BillDeleteForm.tsx b/app/ui/BillDeleteForm.tsx index df76fa0..f12fc50 100644 --- a/app/ui/BillDeleteForm.tsx +++ b/app/ui/BillDeleteForm.tsx @@ -4,22 +4,20 @@ import { FC } from "react"; import { Bill, BillingLocation } from "../lib/db-types"; import { useFormState } from "react-dom"; import { Main } from "./Main"; -import { gotoHome } from "../lib/actions/navigationActions"; import { deleteBillById } from "../lib/actions/billActions"; +import Link from "next/link"; export interface BillDeleteFormProps { bill: Bill, location: BillingLocation } -export const BillDeleteForm:FC = ({ bill, location }) => -{ - const handleAction = deleteBillById.bind(null, location._id, bill._id, location.yearMonth.year, location.yearMonth.month); +export const BillDeleteForm:FC = ({ bill, location }) => { + + const { year, month } = location.yearMonth; + const handleAction = deleteBillById.bind(null, location._id, bill._id, year, month); const [ state, dispatch ] = useFormState(handleAction, null); - const handleCancel = () => { - gotoHome(location.yearMonth); - }; return(
@@ -31,7 +29,7 @@ export const BillDeleteForm:FC = ({ bill, location }) =>

- + Cancel
diff --git a/app/ui/BillEditForm.tsx b/app/ui/BillEditForm.tsx index 443eb02..500ca12 100644 --- a/app/ui/BillEditForm.tsx +++ b/app/ui/BillEditForm.tsx @@ -126,7 +126,7 @@ export const BillEditForm:FC = ({ location, bill }) => {
- + Cancel
diff --git a/app/ui/LocationDeleteForm.tsx b/app/ui/LocationDeleteForm.tsx index 30fe546..ad2f3c8 100644 --- a/app/ui/LocationDeleteForm.tsx +++ b/app/ui/LocationDeleteForm.tsx @@ -6,6 +6,7 @@ import { deleteLocationById } from "../lib/actions/locationActions"; import { useFormState } from "react-dom"; import { Main } from "./Main"; import { gotoUrl } from "../lib/actions/navigationActions"; +import Link from "next/link"; export interface LocationDeleteFormProps { /** location which should be deleted */ @@ -31,7 +32,7 @@ export const LocationDeleteForm:FC = ({ location }) =>

- + Cancel
diff --git a/app/ui/LocationEditForm.tsx b/app/ui/LocationEditForm.tsx index 387dca0..31568d8 100644 --- a/app/ui/LocationEditForm.tsx +++ b/app/ui/LocationEditForm.tsx @@ -8,11 +8,16 @@ import { useFormState } from "react-dom"; import Link from "next/link"; import { gotoHome } from "../lib/actions/navigationActions"; -export interface LocationEditFormProps { +export type LocationEditFormProps = { /** location which should be edited */ - location?: BillingLocation, + location: BillingLocation, /** year adn month at a new billing location should be assigned */ - yearMonth?: YearMonth + yearMonth: undefined +} | { + /** location which should be edited */ + location: undefined, + /** year adn month at a new billing location should be assigned */ + yearMonth: YearMonth } export const LocationEditForm:FC = ({ location, yearMonth }) => @@ -21,14 +26,7 @@ export const LocationEditForm:FC = ({ location, yearMonth const handleAction = updateOrAddLocation.bind(null, location?._id, yearMonth); const [ state, dispatch ] = useFormState(handleAction, initialState); - // redirect to the main page - const handleCancel = () => { - if(location) - gotoHome(location?.yearMonth); - else if(yearMonth) - gotoHome(yearMonth); - - }; + let { year, month } = location ? location.yearMonth : yearMonth; return(
@@ -71,7 +69,7 @@ export const LocationEditForm:FC = ({ location, yearMonth
- + Cancel
@@ -86,10 +84,6 @@ export const LocationEditFormSkeleton:FC = () =>
-
- - -
)