actual/packages/desktop-client/src/components/schedules/index.js
Tom French 9c0df36e16
Sort import in alphabetical order (#238)
* style: enforce sorting of imports

* style: alphabetize imports

* style: merge duplicated imports
2022-09-02 15:07:24 +01:00

81 lines
2 KiB
JavaScript

import React from 'react';
import { useHistory } from 'react-router-dom';
import { useSchedules } from 'loot-core/src/client/data-hooks/schedules';
import { send } from 'loot-core/src/platform/client/fetch';
import { View, Button } from 'loot-design/src/components/common';
import { Page } from '../Page';
import { SchedulesTable, ROW_HEIGHT } from './SchedulesTable';
export default function Schedules() {
let history = useHistory();
let scheduleData = useSchedules();
if (scheduleData == null) {
return null;
}
let { schedules, statuses } = scheduleData;
function onEdit(id) {
history.push(`/schedule/edit/${id}`, { locationPtr: history.location });
}
function onAdd() {
history.push(`/schedule/edit`, { locationPtr: history.location });
}
async function onAction(name, id) {
switch (name) {
case 'post-transaction':
await send('schedule/post-transaction', { id });
break;
case 'skip':
await send('schedule/skip-next-date', { id });
break;
case 'complete':
await send('schedule/update', { schedule: { id, completed: true } });
break;
case 'restart':
await send('schedule/update', {
schedule: { id, completed: false },
resetNextDate: true
});
break;
case 'delete':
await send('schedule/delete', { id });
break;
default:
}
}
return (
<Page title="Schedules">
<View
style={{
marginTop: 20,
flexBasis: (ROW_HEIGHT - 1) * (Math.max(schedules.length, 1) + 1),
overflow: 'hidden'
}}
>
<SchedulesTable
schedules={schedules}
statuses={statuses}
allowCompleted={true}
onSelect={onEdit}
onAction={onAction}
style={{ backgroundColor: 'white' }}
/>
</View>
<View style={{ alignItems: 'flex-end', margin: '20px 0', flexShrink: 0 }}>
<Button primary onClick={onAdd}>
Add new schedule
</Button>
</View>
</Page>
);
}