This commit is contained in:
@@ -42,33 +42,19 @@ const ActivityDetail = () => {
|
||||
queryFn: async () => {
|
||||
try {
|
||||
const res = await getActivityDetail(id);
|
||||
return res.data;
|
||||
const data = res.data;
|
||||
// Map status logic
|
||||
// is_signed_up is only true if status='confirmed'
|
||||
// my_signup_status can be 'unpaid', 'pending', 'confirmed'
|
||||
return data;
|
||||
} catch (err) {
|
||||
throw new Error(err.response?.data?.detail || 'Failed to load activity');
|
||||
}
|
||||
},
|
||||
staleTime: 0, // Ensure fresh data
|
||||
refetchOnMount: 'always', // Force refetch on mount
|
||||
staleTime: 0,
|
||||
refetchOnMount: 'always',
|
||||
});
|
||||
|
||||
//// /
|
||||
// Force a refresh if needed (as requested by user)
|
||||
useEffect(() => {
|
||||
// 1. Force React Query refetch
|
||||
refetch();
|
||||
|
||||
// 2. Hard refresh logic after 1 second delay
|
||||
const timer = setTimeout(() => {
|
||||
const hasRefreshedKey = `has_refreshed_activity_${id}`;
|
||||
if (!sessionStorage.getItem(hasRefreshedKey)) {
|
||||
sessionStorage.setItem(hasRefreshedKey, 'true');
|
||||
window.location.reload();
|
||||
}
|
||||
}, 0);
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
}, [id, refetch]);
|
||||
|
||||
// Auto-fill form fields when the signup form becomes visible
|
||||
useEffect(() => {
|
||||
if (signupFormVisible && user && activity?.signup_form_config) {
|
||||
@@ -162,6 +148,37 @@ const ActivityDetail = () => {
|
||||
return () => clearInterval(timer);
|
||||
}, [paymentModalVisible, paymentInfo, id, queryClient]);
|
||||
|
||||
const getButtonText = () => {
|
||||
if (signUpMutation.isPending) return '提交中...';
|
||||
if (activity.is_signed_up) return '已报名';
|
||||
if (activity.my_signup_status === 'pending') return '审核中';
|
||||
if (activity.my_signup_status === 'unpaid') return '去支付';
|
||||
|
||||
const isEnded = new Date(activity.end_time) < new Date();
|
||||
if (isEnded) return '活动已结束';
|
||||
|
||||
const isFull = activity.max_participants > 0 && (activity.current_signups || 0) >= activity.max_participants;
|
||||
if (isFull) return '名额已满';
|
||||
|
||||
return '立即报名';
|
||||
};
|
||||
|
||||
const isButtonDisabled = () => {
|
||||
if (signUpMutation.isPending) return true;
|
||||
if (activity.is_signed_up) return true;
|
||||
if (activity.my_signup_status === 'pending') return true;
|
||||
// 'unpaid' is NOT disabled, allows payment retry
|
||||
if (activity.my_signup_status === 'unpaid') return false;
|
||||
|
||||
const isEnded = new Date(activity.end_time) < new Date();
|
||||
if (isEnded) return true;
|
||||
|
||||
const isFull = activity.max_participants > 0 && (activity.current_signups || 0) >= activity.max_participants;
|
||||
if (isFull) return true;
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
const handleShare = async () => {
|
||||
const url = window.location.href;
|
||||
if (navigator.share) {
|
||||
@@ -387,11 +404,9 @@ const ActivityDetail = () => {
|
||||
variants={buttonTap}
|
||||
whileTap="tap"
|
||||
onClick={handleSignUp}
|
||||
disabled={signUpMutation.isPending || activity.is_signed_up || (activity.my_signup_status === 'pending' && !activity.is_paid)}
|
||||
disabled={isButtonDisabled()}
|
||||
>
|
||||
{signUpMutation.isPending ? '提交中...' :
|
||||
activity.is_signed_up ? '已报名' :
|
||||
(activity.my_signup_status === 'pending' ? (activity.is_paid ? '去支付' : '审核中') : '立即报名')}
|
||||
{getButtonText()}
|
||||
</motion.button>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user