source: src/sections/invoice/invoice-new-edit-address.tsx@ 5d6f37a

main
Last change on this file since 5d6f37a was 5d6f37a, checked in by Naum Shapkarovski <naumshapkarovski@…>, 7 weeks ago

add customer

  • Property mode set to 100644
File size: 4.4 KB
Line 
1import { useFormContext } from 'react-hook-form';
2// @mui
3import Stack from '@mui/material/Stack';
4import Button from '@mui/material/Button';
5import Divider from '@mui/material/Divider';
6import IconButton from '@mui/material/IconButton';
7import Typography from '@mui/material/Typography';
8// hooks
9import { useGetSettings } from 'src/api/settings';
10import { useBoolean } from 'src/hooks/use-boolean';
11import { useResponsive } from 'src/hooks/use-responsive';
12// components
13import Iconify from 'src/components/iconify';
14//
15import { createFullAddress } from 'src/utils/create-full-address';
16import { useGetCustomers } from 'src/api/customer';
17import { CompanyListDialog } from '../company';
18
19// ----------------------------------------------------------------------
20
21export default function InvoiceNewEditAddress() {
22 const {
23 watch,
24 setValue,
25 formState: { errors },
26 } = useFormContext();
27
28 const mdUp = useResponsive('up', 'md');
29
30 const values = watch();
31
32 const { invoiceFrom, invoiceTo } = values;
33
34 const { settings } = useGetSettings();
35 const { customers } = useGetCustomers();
36
37 const from = useBoolean();
38 const to = useBoolean();
39
40 return (
41 <>
42 <Stack
43 spacing={{ xs: 3, md: 5 }}
44 direction={{ xs: 'column', md: 'row' }}
45 divider={
46 <Divider
47 flexItem
48 orientation={mdUp ? 'vertical' : 'horizontal'}
49 sx={{ borderStyle: 'dashed' }}
50 />
51 }
52 sx={{ p: 3 }}
53 >
54 <Stack sx={{ width: 1 }}>
55 <Stack direction="row" alignItems="center" sx={{ mb: 1 }}>
56 <Typography variant="h6" sx={{ color: 'text.disabled', flexGrow: 1 }}>
57 From:
58 </Typography>
59 <IconButton onClick={from.onTrue}>
60 <Iconify icon="solar:pen-bold" />
61 </IconButton>
62 </Stack>
63
64 {invoiceFrom ? (
65 <Stack spacing={1}>
66 <Typography variant="subtitle2">{invoiceFrom.name}</Typography>
67 <Typography variant="body2">{createFullAddress(invoiceFrom.address)}</Typography>
68 <Typography variant="body2"> {invoiceFrom.phoneNumber}</Typography>
69 </Stack>
70 ) : (
71 <Typography typography="caption" sx={{ color: 'error.main' }}>
72 {(errors.invoiceFrom as any)?.message}
73 </Typography>
74 )}
75 </Stack>
76
77 <Stack sx={{ width: 1 }}>
78 <Stack direction="row" alignItems="center" sx={{ mb: 1 }}>
79 <Typography variant="h6" sx={{ color: 'text.disabled', flexGrow: 1 }}>
80 To:
81 </Typography>
82
83 <IconButton onClick={to.onTrue}>
84 <Iconify icon={invoiceTo ? 'solar:pen-bold' : 'mingcute:add-line'} />
85 </IconButton>
86 </Stack>
87
88 {invoiceTo ? (
89 <Stack spacing={1}>
90 <Typography variant="subtitle2">{invoiceTo.name}</Typography>
91 <Typography variant="body2">{createFullAddress(invoiceTo.address)}</Typography>
92 <Typography variant="body2"> {invoiceTo.phoneNumber}</Typography>
93 </Stack>
94 ) : (
95 <Typography typography="caption" sx={{ color: 'error.main' }}>
96 {(errors.invoiceTo as any)?.message}
97 </Typography>
98 )}
99 </Stack>
100 </Stack>
101
102 {settings && (
103 <CompanyListDialog
104 title="Companies"
105 open={from.value}
106 onClose={from.onFalse}
107 selected={(selectedId: string) => invoiceFrom?.id === selectedId}
108 onSelect={(company) => setValue('invoiceFrom', company)}
109 list={[settings?.company, settings?.['company-ee']]}
110 action={
111 <Button
112 size="small"
113 startIcon={<Iconify icon="mingcute:add-line" />}
114 sx={{ alignSelf: 'flex-end' }}
115 >
116 New
117 </Button>
118 }
119 />
120 )}
121
122 <CompanyListDialog
123 title="Customers"
124 open={to.value}
125 onClose={to.onFalse}
126 selected={(selectedId: string) => invoiceTo?.id === selectedId}
127 onSelect={(company) => setValue('invoiceTo', company)}
128 list={customers}
129 action={
130 <Button
131 size="small"
132 startIcon={<Iconify icon="mingcute:add-line" />}
133 sx={{ alignSelf: 'flex-end' }}
134 >
135 New
136 </Button>
137 }
138 />
139 </>
140 );
141}
Note: See TracBrowser for help on using the repository browser.