Identação de codigo
parent
4cd72fdbd6
commit
64cd155016
|
@ -14,7 +14,7 @@ import DialogActions from "@material-ui/core/DialogActions";
|
||||||
import DialogContent from "@material-ui/core/DialogContent";
|
import DialogContent from "@material-ui/core/DialogContent";
|
||||||
import DialogTitle from "@material-ui/core/DialogTitle";
|
import DialogTitle from "@material-ui/core/DialogTitle";
|
||||||
import Autocomplete, {
|
import Autocomplete, {
|
||||||
createFilterOptions,
|
createFilterOptions,
|
||||||
} from "@material-ui/lab/Autocomplete";
|
} from "@material-ui/lab/Autocomplete";
|
||||||
import CircularProgress from "@material-ui/core/CircularProgress";
|
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||||
|
|
||||||
|
@ -31,177 +31,177 @@ const useStyles = makeStyles((theme) => ({
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const filterOptions = createFilterOptions({
|
const filterOptions = createFilterOptions({
|
||||||
trim: true,
|
trim: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const TransferTicketModal = ({ modalOpen, onClose, ticketid }) => {
|
const TransferTicketModal = ({ modalOpen, onClose, ticketid }) => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const [options, setOptions] = useState([]);
|
const [options, setOptions] = useState([]);
|
||||||
const [queues, setQueues] = useState([]);
|
const [queues, setQueues] = useState([]);
|
||||||
const [allQueues, setAllQueues] = useState([]);
|
const [allQueues, setAllQueues] = useState([]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [searchParam, setSearchParam] = useState("");
|
const [searchParam, setSearchParam] = useState("");
|
||||||
const [selectedUser, setSelectedUser] = useState(null);
|
const [selectedUser, setSelectedUser] = useState(null);
|
||||||
const [selectedQueue, setSelectedQueue] = useState('');
|
const [selectedQueue, setSelectedQueue] = useState('');
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { findAll: findAllQueues } = useQueues();
|
const { findAll: findAllQueues } = useQueues();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadQueues = async () => {
|
const loadQueues = async () => {
|
||||||
const list = await findAllQueues();
|
const list = await findAllQueues();
|
||||||
setAllQueues(list);
|
setAllQueues(list);
|
||||||
setQueues(list);
|
setQueues(list);
|
||||||
}
|
}
|
||||||
loadQueues();
|
loadQueues();
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!modalOpen || searchParam.length < 3) {
|
if (!modalOpen || searchParam.length < 3) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const delayDebounceFn = setTimeout(() => {
|
const delayDebounceFn = setTimeout(() => {
|
||||||
const fetchUsers = async () => {
|
const fetchUsers = async () => {
|
||||||
try {
|
try {
|
||||||
const { data } = await api.get("/users/", {
|
const { data } = await api.get("/users/", {
|
||||||
params: { searchParam },
|
params: { searchParam },
|
||||||
});
|
});
|
||||||
setOptions(data.users);
|
setOptions(data.users);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
toastError(err);
|
toastError(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchUsers();
|
fetchUsers();
|
||||||
}, 500);
|
}, 500);
|
||||||
return () => clearTimeout(delayDebounceFn);
|
return () => clearTimeout(delayDebounceFn);
|
||||||
}, [searchParam, modalOpen]);
|
}, [searchParam, modalOpen]);
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
onClose();
|
onClose();
|
||||||
setSearchParam("");
|
setSearchParam("");
|
||||||
setSelectedUser(null);
|
setSelectedUser(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSaveTicket = async e => {
|
const handleSaveTicket = async e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!ticketid) return;
|
if (!ticketid) return;
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
let data = {};
|
let data = {};
|
||||||
|
|
||||||
if (selectedUser) {
|
if (selectedUser) {
|
||||||
data.userId = selectedUser.id
|
data.userId = selectedUser.id
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedQueue && selectedQueue !== null) {
|
if (selectedQueue && selectedQueue !== null) {
|
||||||
data.queueId = selectedQueue
|
data.queueId = selectedQueue
|
||||||
|
|
||||||
if (!selectedUser) {
|
if (!selectedUser) {
|
||||||
data.status = 'pending';
|
data.status = 'pending';
|
||||||
data.userId = null;
|
data.userId = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// test del PARA APARECER NA FILA DE OUTRO ATENDENTE E O MESMO CLICAR EM ACEITAR AO INVES DE ENVIAR PARA ATENDENDO
|
// test del PARA APARECER NA FILA DE OUTRO ATENDENTE E O MESMO CLICAR EM ACEITAR AO INVES DE ENVIAR PARA ATENDENDO
|
||||||
data.status = 'pending'
|
data.status = 'pending'
|
||||||
|
|
||||||
await api.put(`/tickets/${ticketid}`, data);
|
await api.put(`/tickets/${ticketid}`, data);
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
history.push(`/tickets`);
|
history.push(`/tickets`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
toastError(err);
|
toastError(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={modalOpen} onClose={handleClose} maxWidth="lg" scroll="paper">
|
<Dialog open={modalOpen} onClose={handleClose} maxWidth="lg" scroll="paper">
|
||||||
<form onSubmit={handleSaveTicket}>
|
<form onSubmit={handleSaveTicket}>
|
||||||
<DialogTitle id="form-dialog-title">
|
<DialogTitle id="form-dialog-title">
|
||||||
{i18n.t("transferTicketModal.title")}
|
{i18n.t("transferTicketModal.title")}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogContent dividers>
|
<DialogContent dividers>
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
style={{ width: 300, marginBottom: 20 }}
|
style={{ width: 300, marginBottom: 20 }}
|
||||||
getOptionLabel={option => `${option.name}`}
|
getOptionLabel={option => `${option.name}`}
|
||||||
onChange={(e, newValue) => {
|
onChange={(e, newValue) => {
|
||||||
setSelectedUser(newValue);
|
setSelectedUser(newValue);
|
||||||
if (newValue != null && Array.isArray(newValue.queues)) {
|
if (newValue != null && Array.isArray(newValue.queues)) {
|
||||||
setQueues(newValue.queues);
|
setQueues(newValue.queues);
|
||||||
} else {
|
} else {
|
||||||
setQueues(allQueues);
|
setQueues(allQueues);
|
||||||
setSelectedQueue('');
|
setSelectedQueue('');
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
options={options}
|
options={options}
|
||||||
filterOptions={filterOptions}
|
filterOptions={filterOptions}
|
||||||
freeSolo
|
freeSolo
|
||||||
autoHighlight
|
autoHighlight
|
||||||
noOptionsText={i18n.t("transferTicketModal.noOptions")}
|
noOptionsText={i18n.t("transferTicketModal.noOptions")}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
renderInput={params => (
|
renderInput={params => (
|
||||||
<TextField
|
<TextField
|
||||||
{...params}
|
{...params}
|
||||||
label={i18n.t("transferTicketModal.fieldLabel")}
|
label={i18n.t("transferTicketModal.fieldLabel")}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
required
|
required
|
||||||
autoFocus
|
autoFocus
|
||||||
onChange={e => setSearchParam(e.target.value)}
|
onChange={e => setSearchParam(e.target.value)}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
...params.InputProps,
|
...params.InputProps,
|
||||||
endAdornment: (
|
endAdornment: (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<CircularProgress color="inherit" size={20} />
|
<CircularProgress color="inherit" size={20} />
|
||||||
) : null}
|
) : null}
|
||||||
{params.InputProps.endAdornment}
|
{params.InputProps.endAdornment}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<FormControl variant="outlined" className={classes.maxWidth}>
|
<FormControl variant="outlined" className={classes.maxWidth}>
|
||||||
<InputLabel>{i18n.t("transferTicketModal.fieldQueueLabel")}</InputLabel>
|
<InputLabel>{i18n.t("transferTicketModal.fieldQueueLabel")}</InputLabel>
|
||||||
<Select
|
<Select
|
||||||
value={selectedQueue}
|
value={selectedQueue}
|
||||||
onChange={(e) => setSelectedQueue(e.target.value)}
|
onChange={(e) => setSelectedQueue(e.target.value)}
|
||||||
label={i18n.t("transferTicketModal.fieldQueuePlaceholder")}
|
label={i18n.t("transferTicketModal.fieldQueuePlaceholder")}
|
||||||
>
|
>
|
||||||
<MenuItem value={''}> </MenuItem>
|
<MenuItem value={''}> </MenuItem>
|
||||||
{queues.map((queue) => (
|
{queues.map((queue) => (
|
||||||
<MenuItem key={queue.id} value={queue.id}>{queue.name}</MenuItem>
|
<MenuItem key={queue.id} value={queue.id}>{queue.name}</MenuItem>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleClose}
|
onClick={handleClose}
|
||||||
color="secondary"
|
color="secondary"
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
>
|
>
|
||||||
{i18n.t("transferTicketModal.buttons.cancel")}
|
{i18n.t("transferTicketModal.buttons.cancel")}
|
||||||
</Button>
|
</Button>
|
||||||
<ButtonWithSpinner
|
<ButtonWithSpinner
|
||||||
variant="contained"
|
variant="contained"
|
||||||
type="submit"
|
type="submit"
|
||||||
color="primary"
|
color="primary"
|
||||||
loading={loading}
|
loading={loading}
|
||||||
>
|
>
|
||||||
{i18n.t("transferTicketModal.buttons.ok")}
|
{i18n.t("transferTicketModal.buttons.ok")}
|
||||||
</ButtonWithSpinner>
|
</ButtonWithSpinner>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</form>
|
</form>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default TransferTicketModal;
|
export default TransferTicketModal;
|
||||||
|
|
Loading…
Reference in New Issue