Add پس کرایه checkbox beside shipping price and show it to customers.

Admin can mark a group as freight collect so the amount input is disabled and checkout shows پس کرایه at zero cost.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-10-02 22:37:30 +03:30
co-authored by Cursor
parent 41f21999d2
commit 55071af98c
12 changed files with 200 additions and 99 deletions
@@ -47,6 +47,7 @@ export function ShippingCostGroupModal({
const [description, setDescription] = useState('')
const [methods, setMethods] = useState<ShippingMethodId[]>([])
const [defaultAmount, setDefaultAmount] = useState('')
const [pasKraye, setPasKraye] = useState(false)
const [isDefault, setIsDefault] = useState(false)
const [formError, setFormError] = useState('')
@@ -58,6 +59,7 @@ export function ShippingCostGroupModal({
setNameEn(editingGroup?.nameEn ?? '')
setDescription(editingGroup?.description ?? '')
setMethods(editingGroup?.methods ?? [])
setPasKraye(editingGroup?.pasKraye ?? false)
setDefaultAmount(
editingGroup
? formatIrtInput(String(Math.round(editingGroup.defaultAmount)))
@@ -98,7 +100,7 @@ export function ShippingCostGroupModal({
const trimmedFa = nameFa.trim()
const trimmedEn = nameEn.trim()
const amount = parseIrtInput(defaultAmount)
const amount = pasKraye ? 0 : parseIrtInput(defaultAmount)
if (!trimmedFa || !trimmedEn) {
setFormError(t('store.shipping.form.errorRequired'))
@@ -108,7 +110,7 @@ export function ShippingCostGroupModal({
setFormError(t('store.shipping.form.errorMethods'))
return
}
if (amount === null || amount < 0) {
if (!pasKraye && (amount === null || amount < 0)) {
setFormError(t('store.shipping.form.errorAmount'))
return
}
@@ -118,7 +120,8 @@ export function ShippingCostGroupModal({
nameEn: trimmedEn,
description: description.trim() || undefined,
methods,
defaultAmount: amount,
defaultAmount: amount ?? 0,
pasKraye,
isDefault,
})
}
@@ -244,11 +247,28 @@ export function ShippingCostGroupModal({
placeholder={t('store.shipping.form.defaultAmountPlaceholder')}
value={defaultAmount}
onChange={(e) => setDefaultAmount(formatIrtInput(e.target.value))}
disabled={isSubmitting}
required
disabled={isSubmitting || pasKraye}
required={!pasKraye}
/>
<span className={styles.amountUnit}>IRT</span>
<label className={styles.pasKrayeCheck} htmlFor="shipping-pas-kraye">
<input
id="shipping-pas-kraye"
type="checkbox"
checked={pasKraye}
onChange={(e) => {
const checked = e.target.checked
setPasKraye(checked)
if (checked) setDefaultAmount('')
}}
disabled={isSubmitting}
/>
<span>{t('store.shipping.form.pasKraye')}</span>
</label>
</div>
{pasKraye ? (
<p className={styles.hint}>{t('store.shipping.form.pasKrayeHint')}</p>
) : null}
</div>
<label className={styles.checkRow} htmlFor="shipping-is-default">