1 | import { useFormContext, Controller } from 'react-hook-form';
|
---|
2 | // @mui
|
---|
3 | import { DatePicker } from '@mui/x-date-pickers/DatePicker';
|
---|
4 | import Stack from '@mui/material/Stack';
|
---|
5 | import MenuItem from '@mui/material/MenuItem';
|
---|
6 | // components
|
---|
7 | import { RHFSelect, RHFTextField } from 'src/components/hook-form';
|
---|
8 | // api
|
---|
9 | import { useGetSettings } from 'src/api/settings';
|
---|
10 | // utils
|
---|
11 | import { incrementInvoiceNumber } from 'src/utils/increment-invoice-number';
|
---|
12 |
|
---|
13 | export const monthNames = [
|
---|
14 | 'January',
|
---|
15 | 'February',
|
---|
16 | 'March',
|
---|
17 | 'April',
|
---|
18 | 'May',
|
---|
19 | 'June',
|
---|
20 | 'July',
|
---|
21 | 'August',
|
---|
22 | 'September',
|
---|
23 | 'October',
|
---|
24 | 'November',
|
---|
25 | 'December',
|
---|
26 | ];
|
---|
27 |
|
---|
28 | // ----------------------------------------------------------------------
|
---|
29 |
|
---|
30 | export default function InvoiceNewEditStatusDate({ isCopy }: { isCopy?: boolean }) {
|
---|
31 | const { control, watch } = useFormContext();
|
---|
32 |
|
---|
33 | const values = watch();
|
---|
34 |
|
---|
35 | const { settings } = useGetSettings();
|
---|
36 |
|
---|
37 | return (
|
---|
38 | <Stack
|
---|
39 | spacing={2}
|
---|
40 | direction={{ xs: 'column', sm: 'row' }}
|
---|
41 | sx={{ p: 3, bgcolor: 'background.neutral' }}
|
---|
42 | >
|
---|
43 | {isCopy ? (
|
---|
44 | <RHFTextField
|
---|
45 | disabled
|
---|
46 | name="invoiceNumber"
|
---|
47 | label="Invoice number"
|
---|
48 | value={values.invoiceNumber}
|
---|
49 | />
|
---|
50 | ) : (
|
---|
51 | <RHFTextField name="invoiceNumber" label="Invoice number" value={values.invoiceNumber} />
|
---|
52 | )}
|
---|
53 |
|
---|
54 | <RHFSelect
|
---|
55 | fullWidth
|
---|
56 | name="month"
|
---|
57 | label="Month"
|
---|
58 | InputLabelProps={{ shrink: true }}
|
---|
59 | PaperPropsSx={{ textTransform: 'uppercase' }}
|
---|
60 | >
|
---|
61 | {monthNames.map((option) => (
|
---|
62 | <MenuItem key={option} value={option}>
|
---|
63 | {option}
|
---|
64 | </MenuItem>
|
---|
65 | ))}
|
---|
66 | </RHFSelect>
|
---|
67 |
|
---|
68 | <RHFSelect
|
---|
69 | fullWidth
|
---|
70 | name="status"
|
---|
71 | label="Status"
|
---|
72 | InputLabelProps={{ shrink: true }}
|
---|
73 | PaperPropsSx={{ textTransform: 'capitalize' }}
|
---|
74 | >
|
---|
75 | {['paid', 'pending', 'overdue', 'draft'].map((option) => (
|
---|
76 | <MenuItem key={option} value={option}>
|
---|
77 | {option}
|
---|
78 | </MenuItem>
|
---|
79 | ))}
|
---|
80 | </RHFSelect>
|
---|
81 |
|
---|
82 | <RHFSelect
|
---|
83 | fullWidth
|
---|
84 | name="currency"
|
---|
85 | label="Currency"
|
---|
86 | InputLabelProps={{ shrink: true }}
|
---|
87 | PaperPropsSx={{ textTransform: 'uppercase' }}
|
---|
88 | >
|
---|
89 | {['EUR', 'USD'].map((option) => (
|
---|
90 | <MenuItem key={option} value={option}>
|
---|
91 | {option}
|
---|
92 | </MenuItem>
|
---|
93 | ))}
|
---|
94 | </RHFSelect>
|
---|
95 |
|
---|
96 | <RHFSelect
|
---|
97 | fullWidth
|
---|
98 | name="quantityType"
|
---|
99 | label="Quantity Type"
|
---|
100 | InputLabelProps={{ shrink: true }}
|
---|
101 | PaperPropsSx={{ textTransform: 'uppercase' }}
|
---|
102 | >
|
---|
103 | {['Unit', 'Hour', 'Sprint', 'Month'].map((option) => (
|
---|
104 | <MenuItem key={option} value={option}>
|
---|
105 | {option}
|
---|
106 | </MenuItem>
|
---|
107 | ))}
|
---|
108 | </RHFSelect>
|
---|
109 |
|
---|
110 | <Controller
|
---|
111 | name="createDate"
|
---|
112 | control={control}
|
---|
113 | render={({ field, fieldState: { error } }) => (
|
---|
114 | <DatePicker
|
---|
115 | label="Date issued"
|
---|
116 | value={field.value}
|
---|
117 | onChange={(newValue) => {
|
---|
118 | field.onChange(newValue);
|
---|
119 | }}
|
---|
120 | slotProps={{
|
---|
121 | textField: {
|
---|
122 | fullWidth: true,
|
---|
123 | error: !!error,
|
---|
124 | helperText: error?.message,
|
---|
125 | },
|
---|
126 | }}
|
---|
127 | />
|
---|
128 | )}
|
---|
129 | />
|
---|
130 |
|
---|
131 | <Controller
|
---|
132 | name="dueDate"
|
---|
133 | control={control}
|
---|
134 | render={({ field, fieldState: { error } }) => (
|
---|
135 | <DatePicker
|
---|
136 | label="Due date"
|
---|
137 | value={field.value}
|
---|
138 | onChange={(newValue) => {
|
---|
139 | field.onChange(newValue);
|
---|
140 | }}
|
---|
141 | slotProps={{
|
---|
142 | textField: {
|
---|
143 | fullWidth: true,
|
---|
144 | error: !!error,
|
---|
145 | helperText: error?.message,
|
---|
146 | },
|
---|
147 | }}
|
---|
148 | />
|
---|
149 | )}
|
---|
150 | />
|
---|
151 | </Stack>
|
---|
152 | );
|
---|
153 | }
|
---|