Overview & recent fixes, auth updates, SWR fixes

This commit is contained in:
Darren Clarke 2023-11-10 14:17:09 +01:00
parent 7df947f35a
commit 8d86db882d
29 changed files with 1252 additions and 1221 deletions

View file

@ -8,9 +8,9 @@ import {
DialogActions,
DialogContent,
TextField,
Autocomplete
Autocomplete,
} from "@mui/material";
import { useSWRConfig } from "swr";
import useSWR, { useSWRConfig } from "swr";
import { createTicketMutation } from "app/_graphql/createTicketMutation";
interface TicketCreateDialogProps {
@ -31,8 +31,8 @@ export const TicketCreateDialog: FC<TicketCreateDialogProps> = ({
const [tags, setTags] = useState([]);
const [title, setTitle] = useState("");
const [body, setBody] = useState("");
const backgroundColor = kind === "note" ? "#FFB620" : "#1982FC";
const color = kind === "note" ? "black" : "white";
const backgroundColor = "#1982FC";
const color = "white";
const { fetcher } = useSWRConfig();
const ticket = {
customerId: customerID,
@ -46,16 +46,28 @@ export const TicketCreateDialog: FC<TicketCreateDialogProps> = ({
body,
type: kind,
internal: kind === "note",
}
},
};
const { data: users, error: usersError }: any = useSWR({
url: "/api/v1/users",
method: "GET",
});
console.log({ users, usersError });
const customers =
users?.filter((user: any) => user.role_ids.includes(3)) ?? [];
const formattedCustomers = customers.map((customer: any) => ({
label: customer.login,
id: `${customer.id}`,
}));
const createTicket = async () => {
await fetcher({
document: createTicketMutation,
variables: {
input: {
ticket
ticket,
},
},
});
@ -78,10 +90,13 @@ export const TicketCreateDialog: FC<TicketCreateDialogProps> = ({
<Grid item>
<Autocomplete
disablePortal
options={[{ label: "Test One", id: 1 }, { label: "Test Two", id: 2 }]}
options={formattedCustomers}
value={customerID}
sx={{ width: 300 }}
onChange={(e: any) => setCustomerID(e.target.value)}
renderInput={(params) => <TextField {...params} label="Customer" />}
onChange={(e: any) => setCustomerID(e.target.value.id)}
renderInput={(params) => (
<TextField {...params} label="Customer" />
)}
/>
</Grid>
<Grid item>
@ -129,7 +144,7 @@ export const TicketCreateDialog: FC<TicketCreateDialogProps> = ({
}}
onClick={createTicket}
>
{kind === "note" ? "Save Note" : "Send Reply"}
Create Ticket
</Button>
</Grid>
</Grid>