Fix create-business owner grid and edit renewal date.

Use title/first/last as 3-4-5, repair formFull spans, and fall back renewal to created date.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-08-26 10:33:26 +03:30
co-authored by Cursor
parent e2fb08cccd
commit 58408fed07
2 changed files with 61 additions and 15 deletions
@@ -739,10 +739,18 @@
grid-column: span 2 !important; grid-column: span 2 !important;
} }
.formCol3 {
grid-column: span 3 !important;
}
.formCol4 { .formCol4 {
grid-column: span 4 !important; grid-column: span 4 !important;
} }
.formCol5 {
grid-column: span 5 !important;
}
.formCol8 { .formCol8 {
grid-column: span 8 !important; grid-column: span 8 !important;
} }
@@ -755,8 +763,8 @@
color: var(--text-secondary); color: var(--text-secondary);
} }
.formFull { .formGrid > .formFull {
grid-column: 1 / -1; grid-column: 1 / -1 !important;
} }
.field textarea { .field textarea {
@@ -867,7 +875,9 @@
.formGrid > .field, .formGrid > .field,
.formCol2, .formCol2,
.formCol3,
.formCol4, .formCol4,
.formCol5,
.formCol8 { .formCol8 {
grid-column: 1 / -1 !important; grid-column: 1 / -1 !important;
} }
+49 -13
View File
@@ -125,6 +125,16 @@ function nextAnnualRenewal(contractAt: string, now = new Date()) {
return { next, year: next.getFullYear(), daysRemaining } return { next, year: next.getFullYear(), daysRemaining }
} }
function toDateInputValue(iso: string | null | undefined): string {
if (!iso) return ''
const d = new Date(iso)
if (Number.isNaN(d.getTime())) return ''
const y = d.getFullYear()
const m = String(d.getMonth() + 1).padStart(2, '0')
const day = String(d.getDate()).padStart(2, '0')
return `${y}-${m}-${day}`
}
function renewalTone(daysRemaining: number): 'ok' | 'warn' | 'danger' { function renewalTone(daysRemaining: number): 'ok' | 'warn' | 'danger' {
const months = daysRemaining / 30.437 const months = daysRemaining / 30.437
if (months > 8) return 'ok' if (months > 8) return 'ok'
@@ -132,11 +142,15 @@ function renewalTone(daysRemaining: number): 'ok' | 'warn' | 'danger' {
return 'danger' return 'danger'
} }
function formatRenewalCell(annualRenewalAt: string | null) { function formatRenewalCell(
if (!annualRenewalAt) { annualRenewalAt: string | null,
createdAt?: string | null,
) {
const contractAt = annualRenewalAt || createdAt || null
if (!contractAt) {
return { yearLabel: '—', daysLabel: null as string | null, tone: null as 'ok' | 'warn' | 'danger' | null } return { yearLabel: '—', daysLabel: null as string | null, tone: null as 'ok' | 'warn' | 'danger' | null }
} }
const next = nextAnnualRenewal(annualRenewalAt) const next = nextAnnualRenewal(contractAt)
if (!next) { if (!next) {
return { yearLabel: '—', daysLabel: null, tone: null } return { yearLabel: '—', daysLabel: null, tone: null }
} }
@@ -283,6 +297,7 @@ export function BusinessesPage() {
const [editName, setEditName] = useState('') const [editName, setEditName] = useState('')
const [editNameFa, setEditNameFa] = useState('') const [editNameFa, setEditNameFa] = useState('')
const [editAbout, setEditAbout] = useState('') const [editAbout, setEditAbout] = useState('')
const [editAnnualRenewalAt, setEditAnnualRenewalAt] = useState('')
const [editSubmitting, setEditSubmitting] = useState(false) const [editSubmitting, setEditSubmitting] = useState(false)
const [editError, setEditError] = useState('') const [editError, setEditError] = useState('')
@@ -444,6 +459,9 @@ export function BusinessesPage() {
setEditName(b.name) setEditName(b.name)
setEditNameFa(b.nameFa ?? '') setEditNameFa(b.nameFa ?? '')
setEditAbout(b.about ?? '') setEditAbout(b.about ?? '')
setEditAnnualRenewalAt(
toDateInputValue(b.annualRenewalAt || b.createdAt),
)
setEditError('') setEditError('')
setEditOpen(true) setEditOpen(true)
} }
@@ -650,11 +668,17 @@ export function BusinessesPage() {
setEditSubmitting(true) setEditSubmitting(true)
setEditError('') setEditError('')
const annualRenewalAt = editAnnualRenewalAt
? new Date(editAnnualRenewalAt).toISOString()
: editBusiness.createdAt
? new Date(editBusiness.createdAt).toISOString()
: null
try { try {
await updateBusiness(editBusiness.id, { await updateBusiness(editBusiness.id, {
name, name,
nameFa, nameFa,
about: editAbout.trim(), about: editAbout.trim(),
annualRenewalAt,
}) })
setData((prev) => { setData((prev) => {
if (!prev) return prev if (!prev) return prev
@@ -667,6 +691,7 @@ export function BusinessesPage() {
name, name,
nameFa, nameFa,
about: editAbout.trim() || null, about: editAbout.trim() || null,
annualRenewalAt,
} }
: item, : item,
), ),
@@ -1020,7 +1045,7 @@ export function BusinessesPage() {
setCreateNameFa('') setCreateNameFa('')
setCreateAbout('') setCreateAbout('')
setCreateCategoryIds([]) setCreateCategoryIds([])
setCreateAnnualRenewalAt('') setCreateAnnualRenewalAt(toDateInputValue(new Date().toISOString()))
setCreateOwnerTitleId('') setCreateOwnerTitleId('')
setCreateOwnerFirstName('') setCreateOwnerFirstName('')
setCreateOwnerLastName('') setCreateOwnerLastName('')
@@ -1260,7 +1285,10 @@ export function BusinessesPage() {
{!loading && {!loading &&
data?.items?.map((b) => { data?.items?.map((b) => {
const renewal = formatRenewalCell(b.annualRenewalAt ?? null) const renewal = formatRenewalCell(
b.annualRenewalAt ?? null,
b.createdAt,
)
return ( return (
<tr key={b.id}> <tr key={b.id}>
<td className={styles.td}>{b.name}</td> <td className={styles.td}>{b.name}</td>
@@ -1502,6 +1530,16 @@ export function BusinessesPage() {
disabled={editSubmitting} disabled={editSubmitting}
/> />
</div> </div>
<div className={styles.field}>
<label htmlFor="edit-annual-renewal">Annual renewal</label>
<input
id="edit-annual-renewal"
type="date"
value={editAnnualRenewalAt}
onChange={(e) => setEditAnnualRenewalAt(e.target.value)}
disabled={editSubmitting}
/>
</div>
<div className={styles.field}> <div className={styles.field}>
<label htmlFor="edit-about">About business</label> <label htmlFor="edit-about">About business</label>
<textarea <textarea
@@ -2052,7 +2090,7 @@ export function BusinessesPage() {
<div className={styles.sectionLabel}>Owner</div> <div className={styles.sectionLabel}>Owner</div>
</div> </div>
<div className={`${styles.field} ${styles.formCol2}`}> <div className={`${styles.field} ${styles.formCol3}`}>
<label htmlFor="create-owner-title">Title</label> <label htmlFor="create-owner-title">Title</label>
<select <select
id="create-owner-title" id="create-owner-title"
@@ -2080,7 +2118,7 @@ export function BusinessesPage() {
/> />
</div> </div>
<div className={`${styles.field} ${styles.formCol4}`}> <div className={`${styles.field} ${styles.formCol5}`}>
<label htmlFor="create-owner-last-name-en">Last name (EN)</label> <label htmlFor="create-owner-last-name-en">Last name (EN)</label>
<input <input
id="create-owner-last-name-en" id="create-owner-last-name-en"
@@ -2091,9 +2129,7 @@ export function BusinessesPage() {
/> />
</div> </div>
<div className={`${styles.field} ${styles.formCol2}`} aria-hidden="true" /> <div className={styles.field}>
<div className={`${styles.field} ${styles.formCol4}`}>
<label htmlFor="create-owner-first-name">First name (FA)</label> <label htmlFor="create-owner-first-name">First name (FA)</label>
<input <input
id="create-owner-first-name" id="create-owner-first-name"
@@ -2107,7 +2143,7 @@ export function BusinessesPage() {
/> />
</div> </div>
<div className={`${styles.field} ${styles.formCol4}`}> <div className={styles.field}>
<label htmlFor="create-owner-last-name">Last name (FA)</label> <label htmlFor="create-owner-last-name">Last name (FA)</label>
<input <input
id="create-owner-last-name" id="create-owner-last-name"
@@ -2121,7 +2157,7 @@ export function BusinessesPage() {
/> />
</div> </div>
<div className={`${styles.field} ${styles.formFull}`}> <div className={styles.field}>
<label htmlFor="create-owner-cell">Cell number</label> <label htmlFor="create-owner-cell">Cell number</label>
<input <input
id="create-owner-cell" id="create-owner-cell"
@@ -2134,7 +2170,7 @@ export function BusinessesPage() {
/> />
</div> </div>
<div className={`${styles.field} ${styles.formFull}`}> <div className={styles.field}>
<label htmlFor="create-owner-password">Password</label> <label htmlFor="create-owner-password">Password</label>
<input <input
id="create-owner-password" id="create-owner-password"