feat: 项目接口联调
This commit is contained in:
61
src/features/goods/redeemValidation.ts
Normal file
61
src/features/goods/redeemValidation.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import type {SelectedProductState} from '@/types'
|
||||
|
||||
type RedeemValidationParams = {
|
||||
sessionId?: string
|
||||
selectedProduct: SelectedProductState | null
|
||||
selectedAddressId: string
|
||||
}
|
||||
|
||||
type RedeemValidationResult =
|
||||
| { valid: true }
|
||||
| { valid: false; message: string }
|
||||
|
||||
export function validateRedeemSubmission({
|
||||
sessionId,
|
||||
selectedProduct,
|
||||
selectedAddressId,
|
||||
}: RedeemValidationParams): RedeemValidationResult {
|
||||
if (!sessionId) {
|
||||
return {
|
||||
valid: false,
|
||||
message: 'Session expired. Please log in again.',
|
||||
}
|
||||
}
|
||||
|
||||
if (!selectedProduct) {
|
||||
return {
|
||||
valid: false,
|
||||
message: 'No product selected.',
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedProduct.categoryId === 'PHYSICAL' && !selectedAddressId) {
|
||||
return {
|
||||
valid: false,
|
||||
message: 'Please select a shipping address.',
|
||||
}
|
||||
}
|
||||
|
||||
return {valid: true}
|
||||
}
|
||||
|
||||
type AddAddressValidationParams = {
|
||||
isAddAddressFormValid: boolean
|
||||
}
|
||||
|
||||
type AddAddressValidationResult =
|
||||
| { valid: true }
|
||||
| { valid: false; message: string }
|
||||
|
||||
export function validateAddAddressSubmission({
|
||||
isAddAddressFormValid,
|
||||
}: AddAddressValidationParams): AddAddressValidationResult {
|
||||
if (!isAddAddressFormValid) {
|
||||
return {
|
||||
valid: false,
|
||||
message: 'Please complete all required address fields.',
|
||||
}
|
||||
}
|
||||
|
||||
return {valid: true}
|
||||
}
|
||||
Reference in New Issue
Block a user