-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react' | ||
import { Alert } from 'react-native' | ||
|
||
export default function AreYouSureAlert(msg, dothis) { | ||
return Alert.alert( | ||
"Are your sure?", | ||
msg || "Are you sure you want to perform this action?", | ||
[ | ||
// The "Yes" button | ||
{ | ||
text: "Yes", | ||
onPress: () => { | ||
dothis() | ||
console.log("okkkk"); | ||
}, | ||
}, | ||
// The "No" button | ||
// Does nothing but dismiss the dialog when tapped | ||
{ | ||
text: "No", | ||
}, | ||
] | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,86 @@ | ||
import React from 'react' | ||
import { View, Text } from 'react-native' | ||
import React, { useState, useEffect } from 'react' | ||
import { View, Text, FlatList, StyleSheet, TouchableOpacity } from 'react-native' | ||
import Container from './../../layouts/Container'; | ||
import { StatusBar } from 'expo-status-bar'; | ||
import { useIsFocused } from "@react-navigation/native"; | ||
import Theme from './../../../utils/helpers/Theme'; | ||
import AxiosHelper from './../../../utils/helpers/AxiosHelper'; | ||
import Helper from './../../../utils/helpers/Helper'; | ||
import Icon from './../../layouts/icon/Icon'; | ||
import DefineIcon from './../../layouts/icon/DefineIcon'; | ||
import AreYouSureAlert from './../../layouts/modal/AreYouSureAlert'; | ||
|
||
export default function AllCat() { | ||
const isFocused = useIsFocused(); | ||
const [cat, setCat] = useState([]) | ||
|
||
useEffect(() => { | ||
// console.log("load category") | ||
const token = AxiosHelper.getSource() | ||
const load = async () => { | ||
try { | ||
const uid = await Helper.getUserID() | ||
const data = await AxiosHelper.getData(`pass/get-all-cat/${uid}/`, token) | ||
if (data.success) { | ||
// console.log("data:", data) | ||
setCat(data.object) | ||
} | ||
} catch (e) { | ||
console.log("error HomeScreen.js->", e); | ||
} | ||
} | ||
if (isFocused) { | ||
load() | ||
} | ||
return () => { | ||
token.cancel() | ||
} | ||
}, [isFocused, cat.length]) | ||
|
||
const renderCategory = ({ item }) => { | ||
const onDelete = () => { | ||
console.log(item?._id); | ||
|
||
AreYouSureAlert("Are you sure you want to delete this category?", async () => { | ||
const { success } = await AxiosHelper.deleteData(`pass/del-cat/${item?._id}`) | ||
//console.log("success: ", success); | ||
if (success) { | ||
setCat(old => { | ||
return old.filter((itm) => { | ||
return itm?._id !== item?._id | ||
}) | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
return <TouchableOpacity onPress={onDelete} style={styles.item_container}> | ||
<Text style={{ color: Theme.COLOR_BLACK, fontSize: 18 }}>{item?.title}</Text> | ||
<Icon size={25} name="delete-outline" type={DefineIcon.MaterialIcon} /> | ||
</TouchableOpacity> | ||
} | ||
|
||
return ( | ||
<View> | ||
<Text>Alll Category......</Text> | ||
</View> | ||
<Container style={{ padding: 8 }}> | ||
<StatusBar style={Theme.STATUS_BAR} /> | ||
<FlatList | ||
style={{ paddingTop: 12 }} | ||
data={cat} | ||
renderItem={renderCategory} | ||
ListEmptyComponent={<Text style={{ color: Theme.COLOR_BLACK, padding: 10, textAlign: "center" }}>No Cateogy Found!</Text>} | ||
keyExtractor={item => (String(item._id))} | ||
showsVerticalScrollIndicator={false} | ||
showsHorizontalScrollIndicator={false} | ||
/> | ||
</Container> | ||
) | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
item_container: { | ||
flexDirection: "row", | ||
alignItems: "center", | ||
justifyContent: "space-between", | ||
paddingVertical: 10, | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters