yearMonth split into year + month

This commit is contained in:
2024-01-09 15:43:01 +01:00
parent 90edcf14e1
commit 46b65711a8
12 changed files with 73 additions and 88 deletions

View File

@@ -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: number
/** year at which the new billing location should be addes */
year: number
/** month at which the new billing location should be addes */
month: number
}
export const AddLocationButton:React.FC<AddLocationButtonProps> = ({yyyymm}) =>
export const AddLocationButton:React.FC<AddLocationButtonProps> = ({year,month}) =>
<div className="card card-compact card-bordered max-w-[36em] bg-base-100 shadow-s my-1">
<a href={`/location/${yyyymm}/add`} className="card-body tooltip self-center" data-tip="Add a new billing location">
<a href={`/location/${year}-${month<10?"0":""}${month}/add`} className="card-body tooltip self-center" data-tip="Add a new billing location">
<span className='grid self-center' data-tip="Add a new billing location">
<PlusCircleIcon className="h-[1em] w-[1em] cursor-pointer text-4xl" />
</span>

View File

@@ -2,10 +2,11 @@ import { PlusCircleIcon } from "@heroicons/react/24/outline";
import React from "react";
export interface AddMonthButtonProps {
nextYearMonth: number;
year: number;
month: number;
}
export const AddMonthButton:React.FC<AddMonthButtonProps> = ({ nextYearMonth }) =>
<a href={`/year-month/${nextYearMonth}/add`} className='grid self-center tooltip' data-tip="Dodaj novi mjesec">
export const AddMonthButton:React.FC<AddMonthButtonProps> = ({ year, month }) =>
<a href={`/year-month/${year}-${month<10?"0":""}${month}/add`} className='grid self-center tooltip' data-tip="Dodaj novi mjesec">
<PlusCircleIcon className="h-[1em] w-[1em] cursor-pointer text-4xl" />
</a>

View File

@@ -11,7 +11,7 @@ export interface LocationCardProps {
location: BillingLocation
}
export const LocationCard:FC<LocationCardProps> = ({location: { _id, name, yearMonth, bills }}) => {
export const LocationCard:FC<LocationCardProps> = ({location: { _id, name, year, month, bills }}) => {
// sum all the billAmounts
const monthlyExpense = bills.reduce((acc, bill) => acc + (bill.payedAmount ?? 0), 0);
@@ -22,7 +22,7 @@ export const LocationCard:FC<LocationCardProps> = ({location: { _id, name, yearM
<a href={`/location/${_id}/edit`} className="card-subtitle tooltip" data-tip="Edit Location">
<Cog8ToothIcon className="h-[1em] w-[1em] absolute cursor-pointer top-3 right-3 text-2xl" />
</a>
<h2 className="card-title">{formatYearMonth(yearMonth)} {name}</h2>
<h2 className="card-title">{formatYearMonth(year, month)} {name}</h2>
<div className="card-actions">
{
bills.map(bill => <BillBadge key={`${bill._id}`} locationId={_id} bill={bill} />)

View File

@@ -10,14 +10,16 @@ import { gotoHome } from "../lib/actions/billActions";
export interface LocationEditFormProps {
/** location which should be edited */
location?: BillingLocation,
/** year month at a new billing location should be assigned */
yearMonth?: string
/** year at a new billing location should be assigned */
year?: string
/** month at a new billing location should be assigned */
month?: string
}
export const LocationEditForm:FC<LocationEditFormProps> = ({ location, yearMonth }) =>
export const LocationEditForm:FC<LocationEditFormProps> = ({ location, year, month }) =>
{
const initialState = { message: null, errors: {} };
const handleAction = updateOrAddLocation.bind(null, location?._id, yearMonth);
const handleAction = updateOrAddLocation.bind(null, location?._id, year, month);
const [ state, dispatch ] = useFormState(handleAction, initialState);
// redirect to the main page

View File

@@ -2,8 +2,9 @@ import { FC } from "react";
import { formatYearMonth } from "../lib/format";
export interface MonthTitleProps {
yearMonth: number;
year: number;
month: number;
}
export const MonthTitle:FC<MonthTitleProps> = ({yearMonth}) =>
<div className="divider text-2xl">{`${formatYearMonth(yearMonth)}`}</div>
export const MonthTitle:FC<MonthTitleProps> = ({year, month}) =>
<div className="divider text-2xl">{`${formatYearMonth(year, month)}`}</div>