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(crm): Redirect on company page when deleting an user from company #10103

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
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
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, 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 @@ -155,7 +158,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 @@ -167,6 +170,7 @@ export const ContactAside = ({ link = 'edit' }: { link?: 'edit' | 'show' }) => {
</ReferenceManyField>
<AddTask />
</Box>
<DeleteButton redirect={location.state?.from || undefined} />
arnault-dev marked this conversation as resolved.
Show resolved Hide resolved
</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
Loading