align business logic organizer side
This commit is contained in:
@@ -22,12 +22,14 @@ import Clipboard from '@react-native-clipboard/clipboard';
|
||||
import { CompositeScreenProps, useNavigation } from '@react-navigation/native';
|
||||
import { BottomTabScreenProps } from '@react-navigation/bottom-tabs';
|
||||
// Adjust path
|
||||
import { UPLOAD_GROUP_IMAGE } from '../../utils/ApiUrls';
|
||||
import { BASE_URL, UPLOAD_GROUP_IMAGE } from '../../utils/ApiUrls';
|
||||
import { launchImageLibrary } from 'react-native-image-picker';
|
||||
import *as Keychain from 'react-native-keychain'
|
||||
import Ionicons from '@react-native-vector-icons/ionicons';
|
||||
import { CustomButton } from '../../components/common/Custom';
|
||||
import { StackNavigationProp } from '@react-navigation/stack';
|
||||
import CustomModal from '../../components/common/CustomModal';
|
||||
import WinnerUser from './WinnerUser';
|
||||
|
||||
|
||||
// --- Type Definitions ---
|
||||
@@ -91,7 +93,9 @@ type EditingCard = 'groupInfo' | 'financialRules' | 'configuration' | null;
|
||||
type GroupManagementNavProp = StackNavigationProp<RootStackParamList, 'EditGroup'>;
|
||||
// --- Main Screen Component ---
|
||||
const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
|
||||
const { groupId } = route.params;
|
||||
const { groupId } = route?.params;
|
||||
|
||||
console.log("edit group screen groupId : ", route?.params)
|
||||
const navigation = useNavigation<GroupManagementNavProp>();
|
||||
|
||||
const [editingCard, setEditingCard] = useState<EditingCard>(null);
|
||||
@@ -118,7 +122,8 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
|
||||
const [currentCycle, setCurrentCycle] = useState<number | null>(null);
|
||||
const [selectedImage, setSelectedImage] = useState<string | null>()
|
||||
const [imageUpdating, setImageUpdating] = useState<boolean>(false)
|
||||
|
||||
const [selectedUser, setSelectedUser] = useState() as any
|
||||
const [selectedUserModal, setSelectedUserModel] = useState(false)
|
||||
const initializeEditableData = (data: GroupDetails) => {
|
||||
setEditableData({
|
||||
groupName: data.groupName,
|
||||
@@ -139,8 +144,9 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const response = await apiCall(`https://exotic-humpback-mistakenly.ngrok-free.app/api/fund/group/details?groupId=${groupId}`, 'GET') as { status: string; data?: GroupDetails; message?: string };
|
||||
const response = await apiCall(`${BASE_URL}fund/group/details?groupId=${groupId}`, 'GET') as { status: string; data?: GroupDetails; message?: string };
|
||||
console.log("groupDetails", response)
|
||||
|
||||
if (response.status === 'success' && response.data) {
|
||||
setGroupDetails(response.data);
|
||||
initializeEditableData(response.data);
|
||||
@@ -154,7 +160,7 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
|
||||
}
|
||||
}, [groupId]);
|
||||
// const getPaymentStatus = async()=>{
|
||||
// const response = await apiCall(`https://exotic-humpback-mistakenly.ngrok-free.app/api/payments/group/${groupId}/payment/paid`, 'GET') as { status: string; data?: { currentCycle: number ,status: boolean }; message?: string };
|
||||
// const response = await apiCall(`${BASE_URL}payments/group/${groupId}/payment/paid`, 'GET') as { status: string; data?: { currentCycle: number ,status: boolean }; message?: string };
|
||||
// console.log("paymentStatus",response)
|
||||
// if (response.status === 'success') {
|
||||
// setPaymentStatus(response.data?.status || false);
|
||||
@@ -163,18 +169,22 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
|
||||
// }
|
||||
|
||||
const getPaymentStatus = async () => {
|
||||
const response = await apiCall(`https://exotic-humpback-mistakenly.ngrok-free.app/api/payments/group/${groupId}/payment/paid`, 'GET') as { status: string; data?: { currentCycle: number, allPaid: boolean }; message?: string };
|
||||
const response = await apiCall(`${BASE_URL}payments/group/${groupId}/payment/paid`, 'GET') as { status: string; data?: { currentCycle: number, allPaid: boolean, selectedUser: any }; message?: string };
|
||||
console.log("paymentStatus", response)
|
||||
if (response.status === 'success') {
|
||||
setPaymentStatus(response.data?.allPaid || false);
|
||||
setCurrentCycle(response.data?.currentCycle || null);
|
||||
setSelectedUser(response.data)
|
||||
}
|
||||
}
|
||||
|
||||
console.log("groupid : ", groupId)
|
||||
useEffect(() => {
|
||||
getPaymentStatus()
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
fetchGroupDetails();
|
||||
getPaymentStatus();
|
||||
}, [fetchGroupDetails]);
|
||||
|
||||
|
||||
@@ -197,7 +207,7 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
|
||||
|
||||
setSaving(true);
|
||||
try {
|
||||
await apiCall(`https://exotic-humpback-mistakenly.ngrok-free.app/api/fund/groups/${groupDetails.id}/edit`, 'PUT', editableData);
|
||||
await apiCall(`${BASE_URL}fund/groups/${groupDetails.id}/edit`, 'PUT', editableData);
|
||||
Alert.alert('Success', 'Group has been updated.');
|
||||
setEditingCard(null);
|
||||
await fetchGroupDetails();
|
||||
@@ -207,10 +217,14 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const handleDistribute = async () => {
|
||||
navigation.navigate('RandomSelectUserScreen', { groupId: groupDetails?.id || '', cycleNumber: currentCycle || 0 });
|
||||
navigation.navigate('RandomSelectUserScreen', { groupId , cycleNumber: currentCycle || 0 });
|
||||
};
|
||||
|
||||
|
||||
|
||||
const handleStartGroup = async () => {
|
||||
if (!groupDetails) return;
|
||||
|
||||
@@ -225,9 +239,10 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
|
||||
onPress: async () => {
|
||||
setStarting(true);
|
||||
try {
|
||||
await apiCall(`https://exotic-humpback-mistakenly.ngrok-free.app/api/fund/group/start?groupId=${groupDetails.id}`, 'GET');
|
||||
await apiCall(`${BASE_URL}fund/group/start?groupId=${groupDetails.id}`, 'GET');
|
||||
Alert.alert('Success', 'Group has been started successfully.');
|
||||
await fetchGroupDetails();
|
||||
navigation.goBack()
|
||||
} catch (e: any) {
|
||||
Alert.alert('Start Error', e.message || 'An unexpected error occurred.');
|
||||
} finally {
|
||||
@@ -244,7 +259,7 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
|
||||
if (!groupDetails) return;
|
||||
setInviting(true);
|
||||
try {
|
||||
const response = await apiCall(`https://exotic-humpback-mistakenly.ngrok-free.app/api/invite/generate?groupId=${groupDetails.id}`, 'GET') as { data?: string };
|
||||
const response = await apiCall(`${BASE_URL}invite/generate?groupId=${groupDetails.id}`, 'GET') as { data?: string };
|
||||
|
||||
|
||||
const inviteLink = response.data;
|
||||
@@ -363,6 +378,7 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
|
||||
const isInvitable = groupDetails.status === 'APPROVED';
|
||||
const canStartGroup = groupDetails.status === 'APPROVED' && groupDetails.totalParticipants >= groupDetails.minParticipants;
|
||||
|
||||
console.log(" myu status : ", groupDetails.status)
|
||||
// const pickImage = () => {
|
||||
// launchImageLibrary({ mediaType: "photo", quality: 0.5 }, (response) => {
|
||||
// if (response.didCancel) return;
|
||||
@@ -412,7 +428,7 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
|
||||
|
||||
console.log("✅ Image selected:", {
|
||||
uri: selectedImage.uri,
|
||||
size: (selectedImage.fileSize / 1024).toFixed(2) + "KB",
|
||||
size: (selectedImage?.fileSize / 1024).toFixed(2) + "KB",
|
||||
width: selectedImage.width,
|
||||
height: selectedImage.height
|
||||
});
|
||||
@@ -470,7 +486,7 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
|
||||
|
||||
} catch (error: any) {
|
||||
console.error("❌ Error updating group image:", error);
|
||||
Alert.alert("Error", error.message || "Could not update group image");
|
||||
// Alert.alert("Error", error.message || "Could not update group image");
|
||||
} finally {
|
||||
setImageUpdating(false);
|
||||
}
|
||||
@@ -589,7 +605,7 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
)}
|
||||
{paymentStatus && (
|
||||
{selectedUser?.cycleStatus !== "PENDING_PAYMENTS" && groupDetails.status === 'ACTIVE' &&(
|
||||
<View style={styles.floatingButtonContainer}>
|
||||
<TouchableOpacity
|
||||
style={styles.activateButton}
|
||||
@@ -603,7 +619,24 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
|
||||
)}
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
)}
|
||||
)
|
||||
}
|
||||
|
||||
{
|
||||
selectedUser?.selectedUser !== null && selectedUser?.cycleStatus === "READY_FOR_WITHDRAWAL" && selectedUser?.canProceedToWithdrawal &&
|
||||
<View style={styles.floatingButtonContainer}>
|
||||
<CustomButton
|
||||
buttonBackground={colors?.pastelBlue}
|
||||
style={{ paddingHorizontal: 20 }}
|
||||
title="View Winner of this Cycle"
|
||||
onPress={() => setSelectedUserModel(true)}
|
||||
/>
|
||||
</View>
|
||||
}
|
||||
|
||||
{
|
||||
selectedUserModal && <WinnerUser groupId={groupId} data={selectedUser} visible={selectedUserModal} onClose={() => setSelectedUserModel(false)} />
|
||||
}
|
||||
</AppView>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user