Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function EditLabelModal({ label, mode, onEdit, onAdd, ...props }) {
const { call } = useEventManager();
const { createNotification } = useNotifications();
const reqCreate = useApiWithoutResult(createLabel);
const reqUpdate = useApiWithoutResult(updateLabel);
const I18N = {
edition({ Exclusive } = {}) {
if (Exclusive === LABEL_EXCLUSIVE.LABEL) {
return c('Label/folder modal').t`Edit label`;
}
return c('Label/folder modal').t`Edit folder`;
},
create(label, type) {
if (type === 'label') {
return c('Label/folder modal').t`Create a new label`;
}
return c('Label/folder modal').t`Create a new folder`;
}
};
function AddFilterModal({ filter, type, mode = 'create', onEdit = noop, ...props }) {
const [filterModel] = useState(() => newFilter(filter, type));
const [errors, setErrors] = useState({});
const [model, setModel] = useState(filterModel);
const [isPreview, setPreview] = useState(false);
const [isInvalid, setValitidy] = useState(false);
const [sieveCode, setSieveCode] = useState(filterModel.Sieve || '');
const { call } = useEventManager();
const { createNotification } = useNotifications();
const reqCreate = useApiWithoutResult(addTreeFilter);
const reqUpdate = useApiWithoutResult(updateFilter);
const create = async (filter) => {
const { Filter } = await reqCreate.request(filter);
call();
createNotification({
text: c('Notification').t`${Filter.Name} created`
});
props.onClose();
};
const update = async (filter) => {
const { Filter } = await reqUpdate.request(filter.ID, filter);
call();
createNotification({
text: c('Filter notification').t`Filter ${Filter.Name} updated`
const useFilters = () => {
const { result = {}, loading } = useApiResult(queryFilters, []);
const requestStatus = useApiWithoutResult(toggleEnable);
const requestRemove = useApiWithoutResult(deleteFilter);
const [filerList, setFilters] = useState([]);
useEffect(() => {
setFilters(result.Filters || []);
}, [result.Filters]);
const toggleStatus = async ({ ID }, enable = true) => {
await requestStatus.request(ID, enable);
};
const removeFilter = ({ ID }) => {
setFilters(filerList.filter((filter) => filter.ID !== ID));
};
const LogsSection = () => {
const i18n = getEventsI18N();
const [settings] = useUserSettings();
const { createModal } = useModals();
const [logAuth, setLogAuth] = useState(settings.LogAuth);
const { page, onNext, onPrevious, onSelect } = usePaginationAsync(1);
const { result = {}, loading, request: requestQueryLogs } = useApiResult(
() =>
queryLogs({
Page: page - 1,
PageSize: ELEMENTS_PER_PAGE
}),
[page]
);
const { Logs: logs = [], Total: total = 0 } = result;
const requestDownload = useApiWithoutResult(queryLogs);
const { request: requestClearLogs } = useApiWithoutResult(clearLogs);
const { request: requestUpdateLogAuth } = useApiWithoutResult(updateLogAuth);
const handleWipe = async () => {
await requestClearLogs();
await requestQueryLogs();
};
const handleDownload = async () => {
const { Logs = [] } = await requestDownload.request();
const data = Logs.reduce(
(acc, { Event, Time, IP }) => {
acc.push(`${i18n[Event]},${moment(Time * 1000).toISOString()},${IP}`);
return acc;
},
[['Event', 'Time', 'IP'].join(',')]
function SpamFiltersSection() {
const reqSearch = useApiWithoutResult(getIncomingDefaults);
const { blackList, whiteList, refreshWhiteList, refreshBlackList, move, remove, search, create } = useSpamList();
const { result: white = {}, loading: loadingWhite } = useApiResult(getWhiteList, []);
const { result: black = {}, loading: loadingBlack } = useApiResult(getBlackList, []);
const [loader, setLoader] = useState({});
useEffect(() => {
refreshWhiteList(white.IncomingDefaults || []);
setLoader({ ...loader, white: loadingWhite });
}, [white.IncomingDefaults]);
useEffect(() => {
refreshBlackList(black.IncomingDefaults || []);
setLoader({ ...loader, black: loadingBlack });
}, [black.IncomingDefaults]);