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

Created comments and added functionality to change ticket #61

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ RUN npm config delete proxy
RUN npm install
RUN npm run build

FROM nginx:latest

COPY --from=tres-build-base /app/dist /usr/share/nginx/html
COPY ./etc/www/tres.png /usr/share/nginx/html/tres.png
COPY ./etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
13 changes: 10 additions & 3 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"tooltip": {
"report": "Report ticket",
"suggestion": "Suggestion ticket",
"question": "Question ticket"
"question": "Question ticket",
"notSelected": "Not selected"
}
},
"sidebar": {
Expand All @@ -50,7 +51,8 @@
"scopes": {
"reportTitle": "Report Tickets",
"questionTitle": "Question Tickets",
"suggestionTitle": "Suggestion Tickets"
"suggestionTitle": "Suggestion Tickets",
"notSelectedTitle": "Not selected Tickets"
}
},
"sent": {
Expand Down Expand Up @@ -85,11 +87,16 @@
"additionalInfo": "Additional Information",
"author": "Author",
"faculty": "Faculty",
"dateOfCreation": "Date of creation"
"dateOfCreation": "Date of creation",
"comments": "Comments",
"admin": {
"selectAssignee": "Select assignee"
}
},
"createTicket": {
"heading": "Ticket creation",
"queue": "Queue",
"faculty": "Faculty",
"selectQueue": "Select queue",
"ticketTitle": "Ticket title",
"ticketTitlePlaceholder": "Enter ticket title",
Expand Down
13 changes: 10 additions & 3 deletions public/locales/ua/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"tooltip": {
"report": "Тікет - скарга",
"suggestion": "Тікет - пропозиція",
"question": "Тікет - питання"
"question": "Тікет - питання",
"notSelected": "Не обрано"
}
},
"sidebar": {
Expand All @@ -50,7 +51,8 @@
"scopes": {
"reportTitle": "Тікети - скарги",
"questionTitle": "Тікети - питання",
"suggestionTitle": "Тікети - пропозиції"
"suggestionTitle": "Тікети - пропозиції",
"notSelectedTitle": "Не визначені Тікети"
}
},
"sent": {
Expand Down Expand Up @@ -85,11 +87,16 @@
"additionalInfo": "Додаткова інформація",
"author": "Автор",
"faculty": "Факультет",
"dateOfCreation": "Дата створення"
"dateOfCreation": "Дата створення",
"comments": "Коментарі",
"admin": {
"selectAssignee": "Обери відповідального"
}
},
"createTicket": {
"heading": "Створення тікета",
"queue": "Черга",
"faculty": "Факультет",
"selectQueue": "Оберіть чергу",
"ticketTitle": "Назва тікета",
"ticketTitlePlaceholder": "Введіть назву тікета",
Expand Down
31 changes: 22 additions & 9 deletions src/Pages/CreateTicketForm/CreateTicketForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Grid from "@mui/material/Grid";
import Typography from "@mui/material/Typography";
import useTheme from "@mui/material/styles/useTheme";

import { FacultySelect } from "./components/FacultySelect";
import { QueueSelect } from "./components/QueueSelect";
import { TicketTitleInput } from "./components/TicketTitleInput";
import { TicketBodyTextField } from "./components/TicketBodyTextField";
Expand All @@ -23,7 +24,9 @@ const CreateTicketForm: FC = () => {
const facultyId = getUserFacultyId();

const [selectedOptions, setSelectedOptions] = useState<string[]>([]);
const [queue, setQueue] = useState<number | "none">("none");
const [queue, setQueue] = useState<number>(-1);
const [faculty, setFaculty] = useState<number>(facultyId);
const [formattedText, setFormattedText] = useState("");

const [createTicket] = useCreateTicketMutation();

Expand All @@ -37,16 +40,15 @@ const CreateTicketForm: FC = () => {

const handleClear = (): void => {
resetField("subject");
resetField("body");
setQueue("none");
setValue("queue", null);
setFormattedText("");
setQueue(-1);
setSelectedOptions([]);
};

const onSubmit = (data: ICreateTicketRequestBody): void => {
if (data.queue) {
createTicket({ body: JSON.stringify(data) });
handleClear();
}
createTicket({ body: JSON.stringify(data) });
handleClear();
};

return (
Expand Down Expand Up @@ -75,15 +77,26 @@ const CreateTicketForm: FC = () => {
},
}}
>
<FacultySelect
facultyId={facultyId}
register={register}
setValue={setValue}
faculty={faculty}
setFaculty={setFaculty}
/>
<QueueSelect
faculty={facultyId}
facultyId={faculty}
register={register}
setValue={setValue}
queue={queue}
setQueue={setQueue}
/>
<TicketTitleInput register={register} />
<TicketBodyTextField register={register} />
<TicketBodyTextField
register={register}
formattedText={formattedText}
setFormattedText={setFormattedText}
/>
<TicketVisibilityOptions
setValue={setValue}
selectedOptions={selectedOptions}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { useEffect, FC } from "react";
import { useTranslation } from "react-i18next";
import { UseFormRegister, UseFormSetValue } from "react-hook-form";

import Box from "@mui/material/Box";
import FormControl from "@mui/material/FormControl";
import ListItemText from "@mui/material/ListItemText";
import MenuItem from "@mui/material/MenuItem";
import Select from "@mui/material/Select";
import Typography from "@mui/material/Typography";
import { SelectChangeEvent } from "@mui/material/Select";
import useTheme from "@mui/material/styles/useTheme";

import { Loader } from "../../../../components/Loader";

import { useGetFacultiesQuery } from "../../../../store/api/api";
import IPalette from "../../../../theme/IPalette.interface";

interface FacultySelectProps {
facultyId: number;
faculty: number;
register: UseFormRegister<ICreateTicketRequestBody>;
setValue: UseFormSetValue<ICreateTicketRequestBody>;
setFaculty: (faculty: number) => void;
}

interface faculty {
faculty_id: number;
name: string;
}

const FacultySelect: FC<FacultySelectProps> = ({
facultyId,
register,
setValue,
faculty,
setFaculty,
}) => {
const { t } = useTranslation();
const { palette }: IPalette = useTheme();

const { data, isLoading, isSuccess } = useGetFacultiesQuery({});

const handleChange = (event: SelectChangeEvent): void => {
const selectedFaculty: number = parseInt(event.target.value);

setFaculty(selectedFaculty);
setValue("faculty", selectedFaculty);
};

useEffect(() => {
setValue("faculty", facultyId);
}, []);

return (
<Box>
<Typography variant="h3">{t("createTicket.faculty")}</Typography>
<FormControl
fullWidth
sx={{ bgcolor: palette.grey.card }}
{...register("queue")}
>
{isLoading && <Loader />}
{isSuccess && (
<Select
id="faculty-select"
value={faculty.toString()}
onChange={handleChange}
>
{data.faculties_list.map((faculty: faculty) => {
let isSelected = false;

if (faculty.faculty_id === facultyId) {
isSelected = true;
}

return (
<MenuItem
value={faculty.faculty_id}
key={`menuItem-${faculty.faculty_id}`}
selected={isSelected}
>
<ListItemText primary={faculty.name} />
</MenuItem>
);
})}
</Select>
)}
</FormControl>
</Box>
);
};

export { FacultySelect };
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { FacultySelect } from "./FacultySelect";
18 changes: 8 additions & 10 deletions src/Pages/CreateTicketForm/components/QueueSelect/QueueSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import { useGetQueueByFacultyMutation } from "../../../../store/api/api";
import IPalette from "../../../../theme/IPalette.interface";

interface QueueSelectProps {
faculty: number | null;
facultyId: number | null;
queue: number | "none";
register: UseFormRegister<ICreateTicketRequestBody>;
setValue: UseFormSetValue<ICreateTicketRequestBody>;
setQueue: (queue: number) => void;
}

const QueueSelect: FC<QueueSelectProps> = ({
faculty,
facultyId,
register,
setValue,
queue,
Expand All @@ -42,13 +42,14 @@ const QueueSelect: FC<QueueSelectProps> = ({

const handleChange = (event: SelectChangeEvent): void => {
const selectedQueue: number = parseInt(event.target.value);

setQueue(selectedQueue);
setValue("queue", selectedQueue);
};

useEffect(() => {
faculty && getQueues({ body: JSON.stringify({ faculty: faculty }) });
}, [faculty, getQueues]);
facultyId && getQueues({ body: JSON.stringify({ faculty: facultyId }) });
}, [facultyId, getQueues]);

useEffect(() => {
if (isSuccess) {
Expand All @@ -62,7 +63,7 @@ const QueueSelect: FC<QueueSelectProps> = ({

useEffect(() => {
setValue("queue", null);
}, [setValue]);
}, []);

const menuItems: JSX.Element[] = [];
let currentScope: string | null = null;
Expand Down Expand Up @@ -97,17 +98,14 @@ const QueueSelect: FC<QueueSelectProps> = ({
<FormControl
fullWidth
sx={{ bgcolor: palette.grey.card }}
{...register("queue", {
required: "This is required.",
})}
{...register("queue")}
>
<Select
id="queue-select"
required
value={queue.toString()}
onChange={handleChange}
>
<MenuItem value="none" disabled>
<MenuItem value={-1}>
<ListItemText
primary={t("createTicket.selectQueue")}
primaryTypographyProps={{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { FC, useState, useRef, MutableRefObject } from "react";
import {
FC,
useState,
useRef,
MutableRefObject,
Dispatch,
SetStateAction,
} from "react";
import { useTranslation } from "react-i18next";
import { UseFormRegister } from "react-hook-form";

Expand All @@ -14,16 +21,21 @@ import { MarkdownControls } from "./components/MarkdownControls";

interface TicketBodyTextFieldProps {
register: UseFormRegister<ICreateTicketRequestBody>;
formattedText: string;
setFormattedText: Dispatch<SetStateAction<string>>;
}

const TicketBodyTextField: FC<TicketBodyTextFieldProps> = ({ register }) => {
const TicketBodyTextField: FC<TicketBodyTextFieldProps> = ({
register,
formattedText,
setFormattedText,
}) => {
const { t } = useTranslation();
const { palette }: IPalette = useTheme();

const inputRef: MutableRefObject<null | HTMLInputElement> = useRef(null);

const [isPreview, setIsPreview] = useState(false);
const [formattedText, setFormattedText] = useState("");

const placeholderText: string = t("createTicket.ticketBodyPlaceholder");

Expand Down
2 changes: 1 addition & 1 deletion src/Pages/CreateTicketForm/ticketFormBody.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ interface ICreateTicketRequestBody {
hidden: boolean;
anonymous: boolean;
queue: number | null;
faculty: string;
faculty: number;
}

interface IQueueData {
Expand Down
Loading