Skip to content

Commit

Permalink
Merge pull request #10103 from marmelab/feat/crm-redirect-deleting-co…
Browse files Browse the repository at this point in the history
…ntact

Feat(crm): Redirect on company page when deleting an user from company
  • Loading branch information
jonathanarnault authored Jul 30, 2024
2 parents 79af843 + cdd1d7c commit 164255b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
5 changes: 4 additions & 1 deletion examples/crm/src/companies/CompanyShow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
useRecordContext,
useShowContext,
} from 'react-admin';
import { Link as RouterLink } from 'react-router-dom';
import { Link as RouterLink, useLocation } from 'react-router-dom';

import { ActivityLog } from '../activity/ActivityLog';
import { Avatar } from '../contacts/Avatar';
Expand Down Expand Up @@ -190,7 +190,9 @@ const TabPanel = (props: TabPanelProps) => {
};

const ContactsIterator = () => {
const location = useLocation();
const { data: contacts, error, isPending } = useListContext<Contact>();

if (isPending || error) return null;

const now = Date.now();
Expand All @@ -202,6 +204,7 @@ const ContactsIterator = () => {
button
component={RouterLink}
to={`/contacts/${contact.id}/show`}
state={{ from: location.pathname }}
>
<ListItemAvatar>
<Avatar />
Expand Down
6 changes: 5 additions & 1 deletion examples/crm/src/contacts/ContactAside.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PhoneIcon from '@mui/icons-material/Phone';
import { Box, Divider, Stack, SvgIcon, Typography } from '@mui/material';
import {
DateField,
DeleteButton,
EditButton,
EmailField,
FunctionField,
Expand All @@ -21,8 +22,10 @@ import { TagsListEdit } from './TagsListEdit';

import { useConfigurationContext } from '../root/ConfigurationContext';
import { Contact, Sale } from '../types';
import { useLocation } from 'react-router';

export const ContactAside = ({ link = 'edit' }: { link?: 'edit' | 'show' }) => {
const location = useLocation();
const { contactGender } = useConfigurationContext();
const record = useRecordContext<Contact>();
if (!record) return null;
Expand Down Expand Up @@ -174,7 +177,7 @@ export const ContactAside = ({ link = 'edit' }: { link?: 'edit' | 'show' }) => {
<Divider />
<TagsListEdit />
</Box>
<Box>
<Box mb={3}>
<Typography variant="subtitle2">Tasks</Typography>
<Divider />
<ReferenceManyField
Expand All @@ -186,6 +189,7 @@ export const ContactAside = ({ link = 'edit' }: { link?: 'edit' | 'show' }) => {
</ReferenceManyField>
<AddTask />
</Box>
<DeleteButton redirect={location.state?.from || undefined} />
</Box>
);
};
12 changes: 10 additions & 2 deletions examples/crm/src/contacts/ContactEdit.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import * as React from 'react';
import { EditBase, Form, Toolbar, useEditContext } from 'react-admin';
import {
EditBase,
Form,
SaveButton,
Toolbar,
useEditContext,
} from 'react-admin';
import { Card, CardContent, Box } from '@mui/material';

import { ContactInputs } from './ContactInputs';
Expand All @@ -23,7 +29,9 @@ const ContactEditContent = () => {
<CardContent>
<ContactInputs />
</CardContent>
<Toolbar />
<Toolbar>
<SaveButton />
</Toolbar>
</Card>
</Form>
</Box>
Expand Down

0 comments on commit 164255b

Please sign in to comment.