refactor: improve notification naming and introduce type-safe enums
- Rename billFwd* to billsNotification* for clarity - Rename rentDueNotification* to rentNotification* for consistency - Rename utilBillsProofOfPayment to billsProofOfPayment - Introduce enums for type safety: - BillsNotificationStrategy (WhenPayed, WhenAttached) - BillsNotificationStatus (Scheduled, Sent, Failed) - RentNotificationStatus (Sent, Failed) - Replace "pending" status with "scheduled" for better semantics - Fix function names to proper camelCase - Fix incorrect import path in web-app/app/lib/format.ts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -24,7 +24,7 @@ export const LocationCard: FC<LocationCardProps> = ({ location, currency }) => {
|
||||
bills,
|
||||
seenByTenantAt,
|
||||
// NOTE: only the fileName is projected from the DB to reduce data transfer
|
||||
utilBillsProofOfPayment,
|
||||
billsProofOfPayment,
|
||||
tenantEmail,
|
||||
tenantEmailStatus,
|
||||
} = location;
|
||||
@@ -70,7 +70,7 @@ export const LocationCard: FC<LocationCardProps> = ({ location, currency }) => {
|
||||
</Link>
|
||||
<ShareIcon className="h-[1em] w-[1em] cursor-pointer text-2xl inline hover:text-red-500" title="create sharable link" onClick={handleCopyLinkClick} />
|
||||
</div>
|
||||
{ totalUnpaid > 0 || totalPayed > 0 || seenByTenantAt || utilBillsProofOfPayment?.uploadedAt || (tenantEmail && tenantEmailStatus && tenantEmailStatus !== EmailStatus.Verified) ?
|
||||
{ totalUnpaid > 0 || totalPayed > 0 || seenByTenantAt || billsProofOfPayment?.uploadedAt || (tenantEmail && tenantEmailStatus && tenantEmailStatus !== EmailStatus.Verified) ?
|
||||
<>
|
||||
<div className="flex ml-1">
|
||||
<div className="divider divider-horizontal p-0 m-0"></div>
|
||||
@@ -125,7 +125,7 @@ export const LocationCard: FC<LocationCardProps> = ({ location, currency }) => {
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{utilBillsProofOfPayment?.uploadedAt && (
|
||||
{billsProofOfPayment?.uploadedAt && (
|
||||
<Link
|
||||
href={`/share/proof-of-payment/${_id}/`}
|
||||
target="_blank"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { TrashIcon, ExclamationTriangleIcon, ClockIcon, EnvelopeIcon, CheckCircleIcon, PencilSquareIcon, XCircleIcon } from "@heroicons/react/24/outline";
|
||||
import { FC, useState } from "react";
|
||||
import { BillingLocation, UserSettings, YearMonth, EmailStatus } from '@evidencija-rezija/shared-code';
|
||||
import { BillingLocation, UserSettings, YearMonth, EmailStatus, BillsNotificationStrategy } from '@evidencija-rezija/shared-code';
|
||||
import { updateOrAddLocation } from "../lib/actions/locationActions";
|
||||
import { useFormState } from "react-dom";
|
||||
import Link from "next/link";
|
||||
@@ -45,9 +45,9 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
|
||||
tenantEmailLanguage: location?.tenantEmailLanguage ?? (locale as "hr" | "en"),
|
||||
tenantPaymentMethod: location?.tenantPaymentMethod ?? "none",
|
||||
proofOfPaymentType: location?.proofOfPaymentType ?? "none",
|
||||
billFwdEnabled: location?.billFwdEnabled ?? false,
|
||||
billFwdStrategy: location?.billFwdStrategy ?? "when-payed",
|
||||
rentDueNotificationEnabled: location?.rentDueNotificationEnabled ?? false,
|
||||
billsNotificationEnabled: location?.billsNotificationEnabled ?? false,
|
||||
billsNotificationStrategy: location?.billsNotificationStrategy ?? BillsNotificationStrategy.WhenPayed,
|
||||
rentNotificationEnabled: location?.rentNotificationEnabled ?? false,
|
||||
rentAmount: location?.rentAmount ?? "",
|
||||
rentDueDay: location?.rentDueDay ?? 1,
|
||||
});
|
||||
@@ -279,21 +279,21 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
|
||||
<label className="label cursor-pointer justify-start gap-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="billFwdEnabled"
|
||||
name="billsNotificationEnabled"
|
||||
className="toggle toggle-primary"
|
||||
checked={formValues.billFwdEnabled}
|
||||
onChange={(e) => handleInputChange("billFwdEnabled", e.target.checked)}
|
||||
checked={formValues.billsNotificationEnabled}
|
||||
onChange={(e) => handleInputChange("billsNotificationEnabled", e.target.checked)}
|
||||
/>
|
||||
<legend className="fieldset-legend">{t("auto-utility-bill-forwarding-toggle-label")}</legend>
|
||||
</label>
|
||||
</fieldset>
|
||||
|
||||
{formValues.billFwdEnabled && (
|
||||
{formValues.billsNotificationEnabled && (
|
||||
<fieldset className="fieldset mt-2 p-2">
|
||||
<legend className="fieldset-legend">{t("utility-bill-forwarding-strategy-label")}</legend>
|
||||
<select defaultValue={formValues.billFwdStrategy} className="select input-bordered w-full" name="billFwdStrategy">
|
||||
<option value="when-payed">{t("utility-bill-forwarding-when-payed")}</option>
|
||||
<option value="when-attached">{t("utility-bill-forwarding-when-attached")}</option>
|
||||
<select defaultValue={formValues.billsNotificationStrategy} className="select input-bordered w-full" name="billsNotificationStrategy">
|
||||
<option value={BillsNotificationStrategy.WhenPayed}>{t("utility-bill-forwarding-when-payed")}</option>
|
||||
<option value={BillsNotificationStrategy.WhenAttached}>{t("utility-bill-forwarding-when-attached")}</option>
|
||||
</select>
|
||||
</fieldset>
|
||||
)}
|
||||
@@ -307,16 +307,16 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
|
||||
<label className="label cursor-pointer justify-start gap-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="rentDueNotificationEnabled"
|
||||
name="rentNotificationEnabled"
|
||||
className="toggle toggle-primary"
|
||||
checked={formValues.rentDueNotificationEnabled}
|
||||
onChange={(e) => handleInputChange("rentDueNotificationEnabled", e.target.checked)}
|
||||
checked={formValues.rentNotificationEnabled}
|
||||
onChange={(e) => handleInputChange("rentNotificationEnabled", e.target.checked)}
|
||||
/>
|
||||
<legend className="fieldset-legend">{t("auto-rent-notification-toggle-label")}</legend>
|
||||
</label>
|
||||
</fieldset>
|
||||
|
||||
{formValues.rentDueNotificationEnabled && (
|
||||
{formValues.rentNotificationEnabled && (
|
||||
<div className="animate-expand-fade-in origin-top">
|
||||
<fieldset className="fieldset mt-2 p-2">
|
||||
<legend className="fieldset-legend">{t("rent-due-day-label")}</legend>
|
||||
@@ -356,7 +356,7 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
|
||||
)}
|
||||
</fieldset>
|
||||
|
||||
{(formValues.billFwdEnabled || formValues.rentDueNotificationEnabled) && (
|
||||
{(formValues.billsNotificationEnabled || formValues.rentNotificationEnabled) && (
|
||||
<fieldset className="fieldset bg-base-200 border-base-300 rounded-box w-xs border p-4 pb-2 mt-4">
|
||||
<legend className="fieldset-legend font-semibold uppercase">{t("tenant-email-legend")}</legend>
|
||||
<label className="label">
|
||||
|
||||
@@ -10,7 +10,7 @@ import { ViewBillBadge } from "./ViewBillBadge";
|
||||
import { EncodePayment, PaymentParams } from "hub-3a-payment-encoder";
|
||||
import Link from "next/link";
|
||||
import { LinkIcon } from "@heroicons/react/24/outline";
|
||||
import { uploadUtilBillsProofOfPayment } from "../lib/actions/locationActions";
|
||||
import { uploadBillsProofOfPayment } from "../lib/actions/locationActions";
|
||||
import QRCode from "react-qr-code";
|
||||
import { TicketIcon } from "@heroicons/react/24/solid";
|
||||
import { Pdf417Barcode } from "./Pdf417Barcode";
|
||||
@@ -33,7 +33,7 @@ export const ViewLocationCard: FC<ViewLocationCardProps> = ({ location, userSett
|
||||
tenantTown,
|
||||
tenantPaymentMethod,
|
||||
// NOTE: only the fileName is projected from the DB to reduce data transfer
|
||||
utilBillsProofOfPayment,
|
||||
billsProofOfPayment,
|
||||
proofOfPaymentType,
|
||||
} = location;
|
||||
|
||||
@@ -42,8 +42,8 @@ export const ViewLocationCard: FC<ViewLocationCardProps> = ({ location, userSett
|
||||
|
||||
const [isUploading, setIsUploading] = useState(false);
|
||||
const [uploadError, setUploadError] = useState<string | null>(null);
|
||||
const [attachmentUploadedAt, setAttachmentUploadedAt] = useState<Date | null>(utilBillsProofOfPayment?.uploadedAt ?? null);
|
||||
const [attachmentFilename, setAttachmentFilename] = useState(utilBillsProofOfPayment?.fileName);
|
||||
const [attachmentUploadedAt, setAttachmentUploadedAt] = useState<Date | null>(billsProofOfPayment?.uploadedAt ?? null);
|
||||
const [attachmentFilename, setAttachmentFilename] = useState(billsProofOfPayment?.fileName);
|
||||
|
||||
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
@@ -66,9 +66,9 @@ export const ViewLocationCard: FC<ViewLocationCardProps> = ({ location, userSett
|
||||
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('utilBillsProofOfPayment', file);
|
||||
formData.append('billsProofOfPayment', file);
|
||||
|
||||
const result = await uploadUtilBillsProofOfPayment(shareId, formData);
|
||||
const result = await uploadBillsProofOfPayment(shareId, formData);
|
||||
|
||||
if (result.success) {
|
||||
setAttachmentFilename(file.name);
|
||||
@@ -212,8 +212,8 @@ export const ViewLocationCard: FC<ViewLocationCardProps> = ({ location, userSett
|
||||
</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
id="utilBillsProofOfPayment"
|
||||
name="utilBillsProofOfPayment"
|
||||
id="billsProofOfPayment"
|
||||
name="billsProofOfPayment"
|
||||
type="file"
|
||||
accept="application/pdf"
|
||||
className="file-input file-input-bordered grow file-input-sm my-2 block max-w-[17em] md:max-w-[80em] break-words"
|
||||
|
||||
Reference in New Issue
Block a user