add abbr
This commit is contained in:
@@ -20,6 +20,8 @@ import { Cell } from '../_.$orgid.enrollments.add/route'
|
|||||||
import { CoursePicker } from '../_.$orgid.enrollments.add/course-picker'
|
import { CoursePicker } from '../_.$orgid.enrollments.add/course-picker'
|
||||||
import { MAX_ITEMS, type Course } from '../_.$orgid.enrollments.add/data'
|
import { MAX_ITEMS, type Course } from '../_.$orgid.enrollments.add/data'
|
||||||
import { Discount } from './discount'
|
import { Discount } from './discount'
|
||||||
|
import { Kbd } from '@repo/ui/components/ui/kbd'
|
||||||
|
import { Abbr } from '@repo/ui/components/abbr'
|
||||||
|
|
||||||
const emptyRow = {
|
const emptyRow = {
|
||||||
course: undefined
|
course: undefined
|
||||||
@@ -49,7 +51,7 @@ const formSchema = z.object({
|
|||||||
items: z.array(item).min(1).max(MAX_ITEMS),
|
items: z.array(item).min(1).max(MAX_ITEMS),
|
||||||
coupon: z
|
coupon: z
|
||||||
.object({
|
.object({
|
||||||
coupon: z.string(),
|
code: z.string(),
|
||||||
type: z.enum(['FIXED', 'PERCENT']),
|
type: z.enum(['FIXED', 'PERCENT']),
|
||||||
amount: z.number().positive()
|
amount: z.number().positive()
|
||||||
})
|
})
|
||||||
@@ -219,7 +221,7 @@ export function Bulk({ courses, onSubmit }: BulkProps) {
|
|||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
className="pointer-events-none"
|
className="pointer-events-none"
|
||||||
readOnly
|
readOnly
|
||||||
value={currency.format(course?.unit_price || 0)}
|
value={currency(course?.unit_price || 0)}
|
||||||
/>
|
/>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
|
|
||||||
@@ -233,7 +235,7 @@ export function Bulk({ courses, onSubmit }: BulkProps) {
|
|||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
className="pointer-events-none"
|
className="pointer-events-none"
|
||||||
readOnly
|
readOnly
|
||||||
value={currency.format(
|
value={currency(
|
||||||
(course?.unit_price || 0) *
|
(course?.unit_price || 0) *
|
||||||
(Number.isFinite(quantity) && quantity > 0
|
(Number.isFinite(quantity) && quantity > 0
|
||||||
? quantity
|
? quantity
|
||||||
@@ -288,7 +290,7 @@ export function Bulk({ courses, onSubmit }: BulkProps) {
|
|||||||
<InputGroupInput
|
<InputGroupInput
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
name="subtotal"
|
name="subtotal"
|
||||||
value={currency.format(subtotal)}
|
value={currency(subtotal)}
|
||||||
className="pointer-events-none text-muted-foreground"
|
className="pointer-events-none text-muted-foreground"
|
||||||
readOnly
|
readOnly
|
||||||
/>
|
/>
|
||||||
@@ -298,7 +300,16 @@ export function Bulk({ courses, onSubmit }: BulkProps) {
|
|||||||
{/* Discount */}
|
{/* Discount */}
|
||||||
<>
|
<>
|
||||||
<div className="col-start-3 flex items-center justify-end text-sm font-medium max-lg:hidden">
|
<div className="col-start-3 flex items-center justify-end text-sm font-medium max-lg:hidden">
|
||||||
{coupon ? <>Descontos</> : <>Cupom</>}
|
{coupon ? (
|
||||||
|
<span className="flex gap-1">
|
||||||
|
Descontos
|
||||||
|
<Kbd>
|
||||||
|
<Abbr maxLen={8}>{coupon.code}</Abbr>
|
||||||
|
</Kbd>
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<>Cupom</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<InputGroup>
|
<InputGroup>
|
||||||
@@ -308,7 +319,7 @@ export function Bulk({ courses, onSubmit }: BulkProps) {
|
|||||||
|
|
||||||
<InputGroupInput
|
<InputGroupInput
|
||||||
name="discount"
|
name="discount"
|
||||||
value={currency.format(discount * -1)}
|
value={currency(discount * -1)}
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
className="pointer-events-none text-muted-foreground"
|
className="pointer-events-none text-muted-foreground"
|
||||||
readOnly
|
readOnly
|
||||||
@@ -331,7 +342,7 @@ export function Bulk({ courses, onSubmit }: BulkProps) {
|
|||||||
disabled={subtotal === 0}
|
disabled={subtotal === 0}
|
||||||
onChange={({ sk, discount_amount, discount_type }) => {
|
onChange={({ sk, discount_amount, discount_type }) => {
|
||||||
setValue('coupon', {
|
setValue('coupon', {
|
||||||
coupon: sk,
|
code: sk,
|
||||||
amount: discount_amount,
|
amount: discount_amount,
|
||||||
type: discount_type
|
type: discount_type
|
||||||
})
|
})
|
||||||
@@ -354,7 +365,7 @@ export function Bulk({ courses, onSubmit }: BulkProps) {
|
|||||||
<InputGroupInput
|
<InputGroupInput
|
||||||
name="total"
|
name="total"
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
value={currency.format(total)}
|
value={currency(total)}
|
||||||
className="pointer-events-none text-muted-foreground"
|
className="pointer-events-none text-muted-foreground"
|
||||||
readOnly
|
readOnly
|
||||||
/>
|
/>
|
||||||
@@ -377,11 +388,12 @@ export function Bulk({ courses, onSubmit }: BulkProps) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const currency = new Intl.NumberFormat('pt-BR', {
|
function currency(value: number) {
|
||||||
|
return new Intl.NumberFormat('pt-BR', {
|
||||||
style: 'currency',
|
style: 'currency',
|
||||||
currency: 'BRL'
|
currency: 'BRL'
|
||||||
})
|
}).format(value)
|
||||||
|
}
|
||||||
function applyDiscount(
|
function applyDiscount(
|
||||||
subtotal: number,
|
subtotal: number,
|
||||||
discountAmount: number,
|
discountAmount: number,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { InputHTMLAttributes } from 'react'
|
import type { ButtonHTMLAttributes } from 'react'
|
||||||
import { useRequest, useToggle } from 'ahooks'
|
import { useRequest, useToggle } from 'ahooks'
|
||||||
import { useForm } from 'react-hook-form'
|
import { useForm } from 'react-hook-form'
|
||||||
import { zodResolver } from '@hookform/resolvers/zod'
|
import { zodResolver } from '@hookform/resolvers/zod'
|
||||||
@@ -28,10 +28,11 @@ export const formSchema = z.object({
|
|||||||
export type Schema = z.infer<typeof formSchema>
|
export type Schema = z.infer<typeof formSchema>
|
||||||
|
|
||||||
interface DiscountProps extends Omit<
|
interface DiscountProps extends Omit<
|
||||||
InputHTMLAttributes<HTMLInputElement>,
|
ButtonHTMLAttributes<HTMLButtonElement>,
|
||||||
'value' | 'onChange'
|
'onChange'
|
||||||
> {
|
> {
|
||||||
onChange?: (value: any) => void
|
onChange?: (value: any) => void
|
||||||
|
disabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Discount({ onChange, ...props }: DiscountProps) {
|
export function Discount({ onChange, ...props }: DiscountProps) {
|
||||||
|
|||||||
Reference in New Issue
Block a user