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): Harmonize Sales Form and My Page Form with the others #10091

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion examples/crm/src/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const Header = () => {
/>
{permissions === 'admin' && (
<Tab
label={'Sales'}
label={'Sales Team'}
component={Link}
to="/sales"
value="/sales"
Expand Down
23 changes: 16 additions & 7 deletions examples/crm/src/sales/SalesCreate.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import { Create, PasswordInput, required, SimpleForm } from 'react-admin';
import { SalesForm } from './SalesForm';
import { SalesInputs } from './SalesInputs';
import { Container, Typography } from '@mui/material';

export function SalesCreate() {
return (
<Create redirect="list">
<SimpleForm>
<SalesForm />
<PasswordInput source="password" validate={required()} />
</SimpleForm>
</Create>
<Container maxWidth="sm" sx={{ mt: 4 }}>
<Create redirect="list">
<SimpleForm>
<Typography variant="h6">Create sale guy</Typography>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: I'm not a big fan of sale guy as it is quite informal and gender oriented. Mayby sale person ?

<SalesInputs>
<PasswordInput
source="password"
validate={required()}
helperText={false}
/>
</SalesInputs>
</SimpleForm>
</Create>
</Container>
);
}
27 changes: 21 additions & 6 deletions examples/crm/src/sales/SalesEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
useRecordContext,
} from 'react-admin';
import { Sale } from '../types';
import { SalesForm } from './SalesForm';
import { SalesInputs } from './SalesInputs';
import { Container, Typography } from '@mui/material';

function EditToolbar() {
const { identity } = useGetIdentity();
Expand All @@ -33,14 +34,28 @@ function EditToolbar() {

export function SalesEdit() {
return (
<>
<Container maxWidth="sm" sx={{ mt: 4 }}>
<Edit>
<SimpleForm toolbar={<EditToolbar />}>
<SalesForm />

<PasswordInput source="new_password" />
<SaleEditTitle />
<SalesInputs>
<PasswordInput
source="new_password"
helperText={false}
/>
</SalesInputs>
</SimpleForm>
</Edit>
</>
</Container>
);
}

const SaleEditTitle = () => {
const record = useRecordContext<Sale>();
if (!record) return null;
return (
<Typography variant="h6">
Edit {record?.first_name} {record?.last_name}
</Typography>
);
};
26 changes: 0 additions & 26 deletions examples/crm/src/sales/SalesForm.tsx

This file was deleted.

41 changes: 41 additions & 0 deletions examples/crm/src/sales/SalesInputs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {
BooleanInput,
required,
TextInput,
useGetIdentity,
useRecordContext,
} from 'react-admin';
import { Sale } from '../types';
import { ReactNode } from 'react';
import { Stack } from '@mui/material';

export function SalesInputs({ children }: { children: ReactNode }) {
const { identity } = useGetIdentity();
const record = useRecordContext<Sale>();

return (
<Stack gap={1} sx={{ width: '100%' }}>
<TextInput
source="first_name"
validate={required()}
helperText={false}
/>
<TextInput
source="last_name"
validate={required()}
helperText={false}
/>
<TextInput
source="email"
validate={required()}
helperText={false}
/>
{children}
<BooleanInput
source="administrator"
readOnly={record?.id === identity?.id}
helperText={false}
/>
</Stack>
);
}
4 changes: 2 additions & 2 deletions examples/crm/src/sales/SalesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function SalesListActions() {
return (
<TopToolbar>
<ExportButton />
<CreateButton variant="contained" label="New Sale" />
<CreateButton variant="contained" label="New sales guy" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous comment

</TopToolbar>
);
}
Expand All @@ -34,7 +34,7 @@ export function SalesList() {
<TextField source="first_name" />
<TextField source="last_name" />
<TextField source="email" />
<BooleanField source="administrator" />
<BooleanField source="administrator" FalseIcon={null} />
</DatagridConfigurable>
</List>

Expand Down
2 changes: 1 addition & 1 deletion examples/crm/src/settings/SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const SettingsForm = ({
{isEditMode ? 'Show' : 'Edit'}
</Button>
</Stack>
<Stack gap={2} mb={2}>
<Stack gap={1} mb={2}>
<TextRender source="first_name" isEditMode={isEditMode} />
<TextRender source="last_name" isEditMode={isEditMode} />
<TextRender source="email" isEditMode={isEditMode} />
Expand Down
56 changes: 34 additions & 22 deletions examples/crm/src/settings/UpdatePassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ import {
TextField,
Typography,
} from '@mui/material';
import { useGetIdentity, useGetOne, useNotify, useUpdate } from 'react-admin';
import {
Toolbar,
useGetIdentity,
useGetOne,
useNotify,
useUpdate,
} from 'react-admin';
import { useForm } from 'react-hook-form';
import { DialogCloseButton } from '../misc/DialogCloseButton';

const PASSWORD_POLICY = {
regex: /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/, // Example policy: Minimum 8 characters, at least one letter and one number
Expand Down Expand Up @@ -75,17 +82,18 @@ export const UpdatePassword = ({

return (
<Dialog open={open} onClose={handleClose} maxWidth="sm" fullWidth>
<DialogCloseButton onClose={handleClose} />
<DialogTitle>Change Password</DialogTitle>
<DialogContent>
<Typography
variant="caption"
color="textSecondary"
gutterBottom
>
Password for Jane Doe account is "demo"
</Typography>
<form onSubmit={handleSubmit(onSubmit)}>
<Stack gap={2}>
<form onSubmit={handleSubmit(onSubmit)}>
<DialogContent>
<Typography
variant="caption"
color="textSecondary"
gutterBottom
>
Password for Jane Doe account is "demo"
</Typography>
<Stack gap={1}>
<TextField
{...register('currentPassword', {
required: 'Current password is required',
Expand Down Expand Up @@ -139,14 +147,18 @@ export const UpdatePassword = ({
}
/>
</Stack>
<DialogActions>
<Button
variant="text"
onClick={handleClose}
color="secondary"
>
Cancel
</Button>
</DialogContent>
<DialogActions
sx={{
justifyContent: 'flex-start',
p: 0,
}}
>
<Toolbar
sx={{
width: '100%',
}}
>
<Button
type="submit"
color="primary"
Expand All @@ -155,9 +167,9 @@ export const UpdatePassword = ({
>
Update
</Button>
</DialogActions>
</form>
</DialogContent>
</Toolbar>
</DialogActions>
</form>
</Dialog>
);
};
Loading