Skip to content

Commit

Permalink
Merge branch 'feat/tli-validate-course-session-input' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
TedxTed committed Jan 16, 2025
1 parent ae33129 commit 8610c7d
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,16 @@ const MemberContractCreationForm: React.FC<
const [loading, setLoading] = useState(false)
const [zeroTaxPrice, setZeroTaxPrice] = useState(0)

const validateNumericSessionInput = (value: number) => {
const regex = /^\d+(\.\d{0,1})?$/
if (!regex.test(value.toString())) {
console.error('課程堂數只能輸入小數點後一位')
return false
}

return true
}

const filterProducts = useMemo(() => {
return products.filter(product => {
if (category.project?.includes('自訂')) {
Expand Down Expand Up @@ -930,7 +940,15 @@ const MemberContractCreationForm: React.FC<
value={totalAmount}
step={0.1}
onChange={e => {
setTotalAmount(Number(e))
const numericValue = Number(e)

if (!validateNumericSessionInput(numericValue)) {
return message.error('課程堂數只能輸入小數點後一位')
}

const roundedValue = Math.floor(numericValue * 10) / 10

setTotalAmount(roundedValue)
setCategory({
...category,
name: undefined,
Expand Down

0 comments on commit 8610c7d

Please sign in to comment.