Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(tasks): Update contact last seen when creating a task #61

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/tasks/AddTask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
Stack,
Tooltip,
} from '@mui/material';
import * as React from 'react';
import { useState } from 'react';
import {
AutocompleteInput,
Expand All @@ -24,13 +23,16 @@ import {
TextInput,
Toolbar,
required,
useDataProvider,
useGetIdentity,
useNotify,
useRecordContext,
useUpdate,
} from 'react-admin';
import { useConfigurationContext } from '../root/ConfigurationContext';
import { DialogCloseButton } from '../misc/DialogCloseButton';
import { contactInputText, contactOptionText } from '../misc/ContactOption';
import { Link } from 'react-router-dom';
import { contactInputText, contactOptionText } from '../misc/ContactOption';
import { DialogCloseButton } from '../misc/DialogCloseButton';
import { useConfigurationContext } from '../root/ConfigurationContext';

export const AddTask = ({
selectContact,
Expand All @@ -40,13 +42,32 @@ export const AddTask = ({
display?: 'chip' | 'icon';
}) => {
const { identity } = useGetIdentity();
const dataProvider = useDataProvider();
const [update] = useUpdate();
const notify = useNotify();
const { taskTypes } = useConfigurationContext();
const contact = useRecordContext();
const [open, setOpen] = useState(false);
const handleOpen = () => {
setOpen(true);
};

const handleSuccess = async (data: any) => {
setOpen(false);
const contact = await dataProvider.getOne('contacts', {
id: data.contact_id,
});
if (!contact.data) return;

await update('contacts', {
id: contact.data.id,
data: { last_seen: new Date().toISOString() },
previousData: contact.data,
});

notify('Note added');
};

if (!identity) return null;

return (
Expand Down Expand Up @@ -96,7 +117,7 @@ export const AddTask = ({
due_date: new Date(data.due_date).toISOString(),
};
}}
mutationOptions={{ onSuccess: () => setOpen(false) }}
mutationOptions={{ onSuccess: handleSuccess }}
>
<Dialog
open={open}
Expand Down
Loading