diff --git a/app/lib/locationActions.ts b/app/lib/locationActions.ts index 18749ba..ff60bb6 100644 --- a/app/lib/locationActions.ts +++ b/app/lib/locationActions.ts @@ -30,7 +30,7 @@ const UpdateLocation = FormSchema.omit({ _id: true }); * @param formData form data * @returns */ -export async function updateOrAddLocation(locationId?: string, prevState:State, formData: FormData) { +export async function updateOrAddLocation(locationId?: string, yearMonth?: string, prevState:State, formData: FormData) { const validatedFields = UpdateLocation.safeParse({ locationName: formData.get('locationName'), @@ -65,12 +65,12 @@ export async function updateOrAddLocation(locationId?: string, prevState:State, notes: locationNotes, } }); - } else { + } else if(yearMonth) { await db.collection("lokacije").insertOne({ _id: (new ObjectId()).toHexString(), name: locationName, notes: locationNotes, - yearMonth: 202101, // ToDo: get the current year and month + yearMonth: parseInt(yearMonth), // ToDo: get the current year and month bills: [], }); } diff --git a/app/location/[id]/add/page.tsx b/app/location/[id]/add/page.tsx new file mode 100644 index 0000000..7b7be22 --- /dev/null +++ b/app/location/[id]/add/page.tsx @@ -0,0 +1,6 @@ +import { LocationEditForm } from '@/app/ui/LocationEditForm'; + +export default async function Page({ params:{ id:yearMonth } }: { params: { id:string } }) { + + return (); +} \ No newline at end of file diff --git a/app/page.tsx b/app/page.tsx index f5b7be1..dad454b 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -25,7 +25,7 @@ export const Page = async () => { return ( <> { - location.yearMonth !== array[0].yearMonth && location.yearMonth !== array[ix-1].yearMonth ? : null + location.yearMonth !== array[0].yearMonth && location.yearMonth !== array[ix-1].yearMonth ? : null } { // show month title if it's the first location in the month diff --git a/app/ui/AddLocationButton.tsx b/app/ui/AddLocationButton.tsx index 25cfeac..b3cceef 100644 --- a/app/ui/AddLocationButton.tsx +++ b/app/ui/AddLocationButton.tsx @@ -2,13 +2,15 @@ import { PlusCircleIcon } from "@heroicons/react/24/outline"; export interface AddLocationButtonProps { + /** year month at which the new billing location should be addes */ + yyyymm: string } -export const AddLocationButton:React.FC = () => +export const AddLocationButton:React.FC = ({yyyymm}) =>
-
- - - -
+ + + + +
; \ No newline at end of file diff --git a/app/ui/LocationCard.tsx b/app/ui/LocationCard.tsx index e3c7155..660aabe 100644 --- a/app/ui/LocationCard.tsx +++ b/app/ui/LocationCard.tsx @@ -21,7 +21,7 @@ export const LocationCard:FC = ({location: { _id, name, yearM { bills.map(bill => ) } - + diff --git a/app/ui/LocationEditForm.tsx b/app/ui/LocationEditForm.tsx index cc1b919..3c94036 100644 --- a/app/ui/LocationEditForm.tsx +++ b/app/ui/LocationEditForm.tsx @@ -9,13 +9,15 @@ import { gotoHome } from "../lib/billActions"; export interface LocationEditFormProps { /** location which should be edited */ - location?: BillingLocation + location?: BillingLocation, + /** year month at a new billing location should be assigned */ + yearMonth?: string } -export const LocationEditForm:FC = ({ location }) => +export const LocationEditForm:FC = ({ location, yearMonth }) => { const initialState = { message: null, errors: {} }; - const handleAction = updateOrAddLocation.bind(null, location?._id); + const handleAction = updateOrAddLocation.bind(null, location?._id, yearMonth); const [ state, dispatch ] = useFormState(handleAction, initialState); // redirect to the main page