Skip to content

Commit

Permalink
delete cat done
Browse files Browse the repository at this point in the history
  • Loading branch information
milon27 committed Jul 23, 2021
1 parent cf45555 commit b83fef9
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 11 deletions.
24 changes: 24 additions & 0 deletions src/components/layouts/modal/AreYouSureAlert.js
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",
},
]
);
}
11 changes: 7 additions & 4 deletions src/components/layouts/modal/PasswordModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import ListAction from './../../../utils/context/actions/ListAction';
import { DispatchContext } from './../../../utils/context/MainContext';
import { useNavigation } from '@react-navigation/native';
import URL from './../../../utils/helpers/URL';
import AreYouSureAlert from './AreYouSureAlert';


export default function PasswordModal({ open, setOpen, item }) {
const nav = useNavigation()
const { passDispatch } = useContext(DispatchContext)

const onSubmit = async () => {
const onSubmit = () => {
setOpen(false)
const la = new ListAction(passDispatch)
const val = await la.deleteData('pass/' + item?._id, item?._id)
console.log("del: ", val)
AreYouSureAlert("Are you sure you want to delete this password?", async () => {
const la = new ListAction(passDispatch)
const val = await la.deleteData('pass/' + item?._id, item?._id)
console.log("delete password res : ", val)
})
}
const onEdit = async () => {
setOpen(false)
Expand Down
86 changes: 81 additions & 5 deletions src/components/screens/category/AllCat.js
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,
}
})
4 changes: 2 additions & 2 deletions src/components/screens/dashboard/HomeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ export default function HomeScreen() {
//load category at once

useEffect(() => {
console.log("load category")
// 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)
// console.log("data:", data)
setCat(old => {
return [{
_id: "all_cat",
Expand Down
1 change: 1 addition & 0 deletions src/utils/helpers/AxiosHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const AxiosHelper = {
if (error === false) {
resolve(Response(true, "delete succes", message, Define.BT_SUCCESS, {}));
} else {
console.error("error del : ", res.data)
resolve(
Response(false, "failed", message, Define.BT_DANGER)
);
Expand Down

0 comments on commit b83fef9

Please sign in to comment.