import PageContent from '../../common/PageContent/PageContent';
import HeaderTitle from '../../common/HeaderTitle';
import ConditionallyRender from '../../common/ConditionallyRender/ConditionallyRender';
import {
CREATE_CONTEXT_FIELD,
DELETE_CONTEXT_FIELD,
UPDATE_CONTEXT_FIELD,
} from '../../providers/AccessProvider/permissions';
import {
Button,
IconButton,
List,
ListItem,
ListItemIcon,
ListItemText,
Tooltip,
useMediaQuery,
} from '@material-ui/core';
import { Add, Album, Delete, Edit } from '@material-ui/icons';
import { useContext, useState } from 'react';
import { Link, useHistory } from 'react-router-dom';
import { useStyles } from './styles';
import ConfirmDialogue from '../../common/Dialogue';
import AccessContext from '../../../contexts/AccessContext';
import useUnleashContext from '../../../hooks/api/getters/useUnleashContext/useUnleashContext';
import useContextsApi from '../../../hooks/api/actions/useContextsApi/useContextsApi';
import useToast from '../../../hooks/useToast';
import { formatUnknownError } from '../../../utils/format-unknown-error';
const ContextList = () => {
const { hasAccess } = useContext(AccessContext);
const [showDelDialogue, setShowDelDialogue] = useState(false);
const smallScreen = useMediaQuery('(max-width:700px)');
const [name, setName] = useState();
const { context, refetch } = useUnleashContext();
const { removeContext } = useContextsApi();
const { setToastData, setToastApiError } = useToast();
const history = useHistory();
const styles = useStyles();
const onDeleteContext = async name => {
try {
await removeContext(name);
refetch();
setToastData({
type: 'success',
title: 'Successfully deleted context',
text: 'Your context is now deleted',
});
} catch (error) {
setToastApiError(formatUnknownError(error));
}
setName(undefined);
setShowDelDialogue(false);
};
const contextList = () =>
context.map(field => (
{field.name}
}
elseShow={{field.name}}
/>
}
secondary={field.description}
/>
history.push(`/context/edit/${field.name}`)
}
>
}
/>
{
setName(field.name);
setShowDelDialogue(true);
}}
>
}
/>
));
const headerButton = () => (
history.push('/context/create')}
>
}
elseShow={
}
/>
}
/>
);
return (
}
>
0}
show={contextList}
elseShow={No context fields defined}
/>
onDeleteContext(name)}
onClose={() => {
setName(undefined);
setShowDelDialogue(false);
}}
title="Really delete context field"
/>
);
};
export default ContextList;