year & month replaced by yearMonth object
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
import { PlusCircleIcon } from "@heroicons/react/24/outline";
|
||||
import { YearMonth } from "../lib/db-types";
|
||||
import { formatYearMonth } from "../lib/format";
|
||||
|
||||
|
||||
export interface AddLocationButtonProps {
|
||||
/** year at which the new billing location should be addes */
|
||||
year: number
|
||||
/** month at which the new billing location should be addes */
|
||||
month: number
|
||||
/** year and month at which the new billing location should be addes */
|
||||
yearMonth: YearMonth
|
||||
}
|
||||
|
||||
export const AddLocationButton:React.FC<AddLocationButtonProps> = ({year,month}) =>
|
||||
export const AddLocationButton:React.FC<AddLocationButtonProps> = ({yearMonth}) =>
|
||||
<div className="card card-compact card-bordered max-w-[36em] bg-base-100 shadow-s my-1">
|
||||
<a href={`/location/${year}-${month<10?"0":""}${month}/add`} className="card-body tooltip self-center" data-tip="Add a new billing location">
|
||||
<a href={`/location/${ formatYearMonth(yearMonth) }/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>
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { PlusCircleIcon } from "@heroicons/react/24/outline";
|
||||
import React from "react";
|
||||
import { formatYearMonth } from "../lib/format";
|
||||
import { YearMonth } from "../lib/db-types";
|
||||
|
||||
export interface AddMonthButtonProps {
|
||||
year: number;
|
||||
month: number;
|
||||
yearMonth: YearMonth;
|
||||
}
|
||||
|
||||
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">
|
||||
export const AddMonthButton:React.FC<AddMonthButtonProps> = ({ yearMonth }) =>
|
||||
<a href={`/year-month/${formatYearMonth(yearMonth)}/add`} className='grid self-center tooltip' data-tip="Dodaj novi mjesec">
|
||||
<PlusCircleIcon className="h-[1em] w-[1em] cursor-pointer text-4xl" />
|
||||
</a>
|
||||
|
||||
@@ -11,7 +11,7 @@ export interface LocationCardProps {
|
||||
location: BillingLocation
|
||||
}
|
||||
|
||||
export const LocationCard:FC<LocationCardProps> = ({location: { _id, name, year, month, bills }}) => {
|
||||
export const LocationCard:FC<LocationCardProps> = ({location: { _id, name, yearMonth, 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, year,
|
||||
<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(year, month)} {name}</h2>
|
||||
<h2 className="card-title">{formatYearMonth(yearMonth)} {name}</h2>
|
||||
<div className="card-actions">
|
||||
{
|
||||
bills.map(bill => <BillBadge key={`${bill._id}`} locationId={_id} bill={bill} />)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { TrashIcon } from "@heroicons/react/24/outline";
|
||||
import { FC } from "react";
|
||||
import { BillingLocation } from "../lib/db-types";
|
||||
import { BillingLocation, YearMonth } from "../lib/db-types";
|
||||
import { updateOrAddLocation } from "../lib/actions/locationActions";
|
||||
import { useFormState } from "react-dom";
|
||||
import { gotoHome } from "../lib/actions/billActions";
|
||||
@@ -10,16 +10,14 @@ import { gotoHome } from "../lib/actions/billActions";
|
||||
export interface LocationEditFormProps {
|
||||
/** location which should be edited */
|
||||
location?: BillingLocation,
|
||||
/** year at a new billing location should be assigned */
|
||||
year?: string
|
||||
/** month at a new billing location should be assigned */
|
||||
month?: string
|
||||
/** year adn month at a new billing location should be assigned */
|
||||
yearMonth?: YearMonth
|
||||
}
|
||||
|
||||
export const LocationEditForm:FC<LocationEditFormProps> = ({ location, year, month }) =>
|
||||
export const LocationEditForm:FC<LocationEditFormProps> = ({ location, yearMonth }) =>
|
||||
{
|
||||
const initialState = { message: null, errors: {} };
|
||||
const handleAction = updateOrAddLocation.bind(null, location?._id, year, month);
|
||||
const handleAction = updateOrAddLocation.bind(null, location?._id, yearMonth);
|
||||
const [ state, dispatch ] = useFormState(handleAction, initialState);
|
||||
|
||||
// redirect to the main page
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { FC } from "react";
|
||||
import { formatYearMonth } from "../lib/format";
|
||||
import { YearMonth } from "../lib/db-types";
|
||||
|
||||
export interface MonthTitleProps {
|
||||
year: number;
|
||||
month: number;
|
||||
yearMonth: YearMonth
|
||||
}
|
||||
|
||||
export const MonthTitle:FC<MonthTitleProps> = ({year, month}) =>
|
||||
<div className="divider text-2xl">{`${formatYearMonth(year, month)}`}</div>
|
||||
export const MonthTitle:FC<MonthTitleProps> = ({ yearMonth }) =>
|
||||
<div className="divider text-2xl">{`${formatYearMonth(yearMonth)}`}</div>
|
||||
Reference in New Issue
Block a user