mirror of
https://github.com/hazemKrimi/crimson-quirks-ui.git
synced 2026-05-01 18:20:28 +00:00
Add delete category functionality
This commit is contained in:
@@ -13,17 +13,21 @@ import {
|
|||||||
Alert,
|
Alert,
|
||||||
TextArea,
|
TextArea,
|
||||||
Spinner,
|
Spinner,
|
||||||
|
Modal,
|
||||||
} from '../../components';
|
} from '../../components';
|
||||||
import { Wrapper } from './styles';
|
import { Wrapper } from './styles';
|
||||||
import { ArrowLeft, General } from '../../assets';
|
import { ArrowLeft, General } from '../../assets';
|
||||||
import {
|
import {
|
||||||
CategoryOutput,
|
CategoryOutput,
|
||||||
|
DeleteCategoryMutation,
|
||||||
|
DeleteCategoryMutationVariables,
|
||||||
GetCategoryByIdQuery,
|
GetCategoryByIdQuery,
|
||||||
GetCategoryByIdQueryVariables,
|
GetCategoryByIdQueryVariables,
|
||||||
UpdateCategoryMutation,
|
UpdateCategoryMutation,
|
||||||
UpdateCategoryMutationVariables,
|
UpdateCategoryMutationVariables,
|
||||||
} from '../../graphql/types';
|
} from '../../graphql/types';
|
||||||
import {
|
import {
|
||||||
|
DELETE_CATEGORY,
|
||||||
GET_CATEGORY_BY_ID,
|
GET_CATEGORY_BY_ID,
|
||||||
UPDATE_CATEGORY,
|
UPDATE_CATEGORY,
|
||||||
} from '../../graphql/category.api';
|
} from '../../graphql/category.api';
|
||||||
@@ -37,6 +41,10 @@ const CategorySettings = () => {
|
|||||||
const [success, setSuccess] = useState<boolean>(false);
|
const [success, setSuccess] = useState<boolean>(false);
|
||||||
const [category, setCategory] = useState<CategoryOutput>();
|
const [category, setCategory] = useState<CategoryOutput>();
|
||||||
|
|
||||||
|
const [deleteCategoryModal, setDeleteCategoryModal] = useState<boolean>(
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
const [getCategory, { loading: categoryLoading }] = useLazyQuery<
|
const [getCategory, { loading: categoryLoading }] = useLazyQuery<
|
||||||
GetCategoryByIdQuery,
|
GetCategoryByIdQuery,
|
||||||
GetCategoryByIdQueryVariables
|
GetCategoryByIdQueryVariables
|
||||||
@@ -61,6 +69,19 @@ const CategorySettings = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [deleteCategory] = useMutation<
|
||||||
|
DeleteCategoryMutation,
|
||||||
|
DeleteCategoryMutationVariables
|
||||||
|
>(DELETE_CATEGORY, {
|
||||||
|
onCompleted() {
|
||||||
|
history.push('/category');
|
||||||
|
},
|
||||||
|
onError({ graphQLErrors }) {
|
||||||
|
setError(graphQLErrors[0]?.extensions?.info);
|
||||||
|
setTimeout(() => setError(''), 3000);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getCategory({ variables: { id } });
|
getCategory({ variables: { id } });
|
||||||
|
|
||||||
@@ -97,6 +118,16 @@ const CategorySettings = () => {
|
|||||||
|
|
||||||
return role === 'developer' ? (
|
return role === 'developer' ? (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
|
{deleteCategoryModal && (
|
||||||
|
<Modal
|
||||||
|
color={role || 'client'}
|
||||||
|
title='Delete Category'
|
||||||
|
description='
|
||||||
|
If you delete this category you cannot recover it.'
|
||||||
|
onClose={() => setDeleteCategoryModal(false)}
|
||||||
|
onConfirm={() => deleteCategory({ variables: { id } })}
|
||||||
|
></Modal>
|
||||||
|
)}
|
||||||
<Box>
|
<Box>
|
||||||
<Button
|
<Button
|
||||||
text='Back'
|
text='Back'
|
||||||
@@ -207,8 +238,14 @@ const CategorySettings = () => {
|
|||||||
<Box
|
<Box
|
||||||
marginTop='0.5rem'
|
marginTop='0.5rem'
|
||||||
display='flex'
|
display='flex'
|
||||||
justifyContent='flex-end'
|
justifyContent='space-between'
|
||||||
>
|
>
|
||||||
|
<Button
|
||||||
|
variant='text'
|
||||||
|
color='error'
|
||||||
|
text='Delete Category'
|
||||||
|
onClick={() => setDeleteCategoryModal(true)}
|
||||||
|
/>
|
||||||
<Button
|
<Button
|
||||||
variant='primary-action'
|
variant='primary-action'
|
||||||
color={role || 'client'}
|
color={role || 'client'}
|
||||||
|
|||||||
Reference in New Issue
Block a user