Merge branch 'develop' into feature-paypal-simple
This commit is contained in:
@@ -76,7 +76,7 @@ export default function InteractiveSpeaking({
|
|||||||
onBack({
|
onBack({
|
||||||
exercise: id,
|
exercise: id,
|
||||||
solutions: [...answers.filter((x) => x.questionIndex !== questionIndex), answer],
|
solutions: [...answers.filter((x) => x.questionIndex !== questionIndex), answer],
|
||||||
score: {correct: 1, total: 1, missing: 0},
|
score: {correct: 100, total: 100, missing: 0},
|
||||||
type,
|
type,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -96,7 +96,7 @@ export default function InteractiveSpeaking({
|
|||||||
onNext({
|
onNext({
|
||||||
exercise: id,
|
exercise: id,
|
||||||
solutions: [...answers.filter((x) => x.questionIndex !== questionIndex), answer],
|
solutions: [...answers.filter((x) => x.questionIndex !== questionIndex), answer],
|
||||||
score: {correct: 1, total: 1, missing: 0},
|
score: {correct: 100, total: 100, missing: 0},
|
||||||
type,
|
type,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -131,7 +131,7 @@ export default function InteractiveSpeaking({
|
|||||||
onNext({
|
onNext({
|
||||||
exercise: id,
|
exercise: id,
|
||||||
solutions: [...answers.filter((x) => x.questionIndex !== questionIndex), answer],
|
solutions: [...answers.filter((x) => x.questionIndex !== questionIndex), answer],
|
||||||
score: {correct: 1, total: 1, missing: 0},
|
score: {correct: 100, total: 100, missing: 0},
|
||||||
type,
|
type,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -176,7 +176,7 @@ export default function InteractiveSpeaking({
|
|||||||
{
|
{
|
||||||
exercise: id,
|
exercise: id,
|
||||||
solutions: [...answers.filter((x) => x.questionIndex !== questionIndex), answer],
|
solutions: [...answers.filter((x) => x.questionIndex !== questionIndex), answer],
|
||||||
score: {correct: 1, total: 1, missing: 0},
|
score: {correct: 100, total: 100, missing: 0},
|
||||||
module: "speaking",
|
module: "speaking",
|
||||||
exam: examID,
|
exam: examID,
|
||||||
type,
|
type,
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ export default function Speaking({id, title, text, video_url, type, prompts, use
|
|||||||
onNext({
|
onNext({
|
||||||
exercise: id,
|
exercise: id,
|
||||||
solutions: storagePath ? [{id, solution: storagePath}] : [],
|
solutions: storagePath ? [{id, solution: storagePath}] : [],
|
||||||
score: {correct: 1, total: 1, missing: 0},
|
score: {correct: 100, total: 100, missing: 0},
|
||||||
type,
|
type,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -94,7 +94,7 @@ export default function Speaking({id, title, text, video_url, type, prompts, use
|
|||||||
onBack({
|
onBack({
|
||||||
exercise: id,
|
exercise: id,
|
||||||
solutions: storagePath ? [{id, solution: storagePath}] : [],
|
solutions: storagePath ? [{id, solution: storagePath}] : [],
|
||||||
score: {correct: 1, total: 1, missing: 0},
|
score: {correct: 100, total: 100, missing: 0},
|
||||||
type,
|
type,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export default function Writing({
|
|||||||
if (inputText.length > 0 && saveTimer % 10 === 0) {
|
if (inputText.length > 0 && saveTimer % 10 === 0) {
|
||||||
setUserSolutions([
|
setUserSolutions([
|
||||||
...storeUserSolutions.filter((x) => x.exercise !== id),
|
...storeUserSolutions.filter((x) => x.exercise !== id),
|
||||||
{exercise: id, solutions: [{id, solution: inputText}], score: {correct: 1, total: 1, missing: 0}, type, module: "writing"},
|
{exercise: id, solutions: [{id, solution: inputText}], score: {correct: 100, total: 100, missing: 0}, type, module: "writing"},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
@@ -65,7 +65,7 @@ export default function Writing({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (hasExamEnded)
|
if (hasExamEnded)
|
||||||
onNext({exercise: id, solutions: [{id, solution: inputText}], score: {correct: 1, total: 1, missing: 0}, type, module: "writing"});
|
onNext({exercise: id, solutions: [{id, solution: inputText}], score: {correct: 100, total: 100, missing: 0}, type, module: "writing"});
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [hasExamEnded]);
|
}, [hasExamEnded]);
|
||||||
|
|
||||||
@@ -148,7 +148,9 @@ export default function Writing({
|
|||||||
<Button
|
<Button
|
||||||
color="purple"
|
color="purple"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={() => onBack({exercise: id, solutions: [{id, solution: inputText}], score: {correct: 1, total: 1, missing: 0}, type})}
|
onClick={() =>
|
||||||
|
onBack({exercise: id, solutions: [{id, solution: inputText}], score: {correct: 100, total: 100, missing: 0}, type})
|
||||||
|
}
|
||||||
className="max-w-[200px] self-end w-full">
|
className="max-w-[200px] self-end w-full">
|
||||||
Back
|
Back
|
||||||
</Button>
|
</Button>
|
||||||
@@ -159,7 +161,7 @@ export default function Writing({
|
|||||||
onNext({
|
onNext({
|
||||||
exercise: id,
|
exercise: id,
|
||||||
solutions: [{id, solution: inputText.replaceAll(/\s{2,}/g, " ")}],
|
solutions: [{id, solution: inputText.replaceAll(/\s{2,}/g, " ")}],
|
||||||
score: {correct: 1, total: 1, missing: 0},
|
score: {correct: 100, total: 100, missing: 0},
|
||||||
type,
|
type,
|
||||||
module: "writing",
|
module: "writing",
|
||||||
})
|
})
|
||||||
|
|||||||
23
src/hooks/usePaypalPayments.tsx
Normal file
23
src/hooks/usePaypalPayments.tsx
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import {PaypalPayment} from "@/interfaces/paypal";
|
||||||
|
import axios from "axios";
|
||||||
|
import {useEffect, useState} from "react";
|
||||||
|
|
||||||
|
export default function usePaypalPayments() {
|
||||||
|
const [payments, setPayments] = useState<PaypalPayment[]>([]);
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [isError, setIsError] = useState(false);
|
||||||
|
|
||||||
|
const getData = () => {
|
||||||
|
setIsLoading(true);
|
||||||
|
axios
|
||||||
|
.get<PaypalPayment[]>("/api/payments/paypal")
|
||||||
|
.then((response) => {
|
||||||
|
return setPayments(response.data);
|
||||||
|
})
|
||||||
|
.finally(() => setIsLoading(false));
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(getData, []);
|
||||||
|
|
||||||
|
return {payments, isLoading, isError, reload: getData};
|
||||||
|
}
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
import { Ticket } from "@/interfaces/ticket";
|
import { TicketWithCorporate } from "@/interfaces/ticket";
|
||||||
import { Code, Group, User } from "@/interfaces/user";
|
import { Code, Group, User } from "@/interfaces/user";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
|
|
||||||
export default function useTickets() {
|
export default function useTickets() {
|
||||||
const [tickets, setTickets] = useState<Ticket[]>([]);
|
const [tickets, setTickets] = useState<TicketWithCorporate[]>([]);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [isError, setIsError] = useState(false);
|
const [isError, setIsError] = useState(false);
|
||||||
|
|
||||||
const getData = useCallback(() => {
|
const getData = useCallback(() => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
axios
|
axios
|
||||||
.get<Ticket[]>(`/api/tickets`)
|
.get<TicketWithCorporate[]>(`/api/tickets`)
|
||||||
.then((response) => setTickets(response.data))
|
.then((response) => setTickets(response.data))
|
||||||
.finally(() => setIsLoading(false));
|
.finally(() => setIsLoading(false));
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
@@ -35,3 +35,16 @@ export interface Payment {
|
|||||||
corporateTransfer?: string;
|
corporateTransfer?: string;
|
||||||
commissionTransfer?: string;
|
commissionTransfer?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface PaypalPayment {
|
||||||
|
orderId: string;
|
||||||
|
userId: string;
|
||||||
|
status: string;
|
||||||
|
createdAt: Date;
|
||||||
|
value: number;
|
||||||
|
currency: string;
|
||||||
|
subscriptionDuration: number;
|
||||||
|
subscriptionDurationUnit: DurationUnit;
|
||||||
|
subscriptionExpirationDate: Date;
|
||||||
|
}
|
||||||
@@ -32,3 +32,7 @@ export const TicketStatusLabel: { [key in TicketStatus]: string } = {
|
|||||||
"in-progress": "In Progress",
|
"in-progress": "In Progress",
|
||||||
completed: "Completed",
|
completed: "Completed",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export interface TicketWithCorporate extends Ticket {
|
||||||
|
corporate?: string;
|
||||||
|
}
|
||||||
@@ -424,7 +424,7 @@ export default function ExamPage({page}: Props) {
|
|||||||
<AbandonPopup
|
<AbandonPopup
|
||||||
isOpen={showAbandonPopup}
|
isOpen={showAbandonPopup}
|
||||||
abandonPopupTitle="Leave Exercise"
|
abandonPopupTitle="Leave Exercise"
|
||||||
abandonPopupDescription="Are you sure you want to leave the exercise? You will lose all your progress."
|
abandonPopupDescription="Are you sure you want to leave the exercise? Your progress will be saved and this exam can be resumed on the Dashboard."
|
||||||
abandonConfirmButtonText="Confirm"
|
abandonConfirmButtonText="Confirm"
|
||||||
onAbandon={() => {
|
onAbandon={() => {
|
||||||
reset();
|
reset();
|
||||||
|
|||||||
30
src/pages/api/payments/paypal.ts
Normal file
30
src/pages/api/payments/paypal.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||||
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
import { app } from "@/firebase";
|
||||||
|
import {
|
||||||
|
getFirestore,
|
||||||
|
getDocs,
|
||||||
|
collection,
|
||||||
|
} from "firebase/firestore";
|
||||||
|
import { withIronSessionApiRoute } from "iron-session/next";
|
||||||
|
import { sessionOptions } from "@/lib/session";
|
||||||
|
|
||||||
|
const db = getFirestore(app);
|
||||||
|
|
||||||
|
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||||
|
|
||||||
|
async function get(req: NextApiRequest, res: NextApiResponse) {
|
||||||
|
const payments = await getDocs(collection(db, "paypalpayments"));
|
||||||
|
|
||||||
|
const data = payments.docs.map((doc) => doc.data());
|
||||||
|
res.status(200).json(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
|
if (!req.session.user) {
|
||||||
|
res.status(401).json({ ok: false });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req.method === "GET") await get(req, res);
|
||||||
|
}
|
||||||
@@ -74,6 +74,25 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
{ merge: true }
|
{ merge: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await setDoc(
|
||||||
|
doc(db, 'paypalpayments', v4()),
|
||||||
|
{
|
||||||
|
orderId: id,
|
||||||
|
userId: req.session.user.id,
|
||||||
|
status: request.data.status,
|
||||||
|
createdAt: new Date().toISOString(),
|
||||||
|
value: request.data.purchase_units[0].payments.captures[0].amount.value,
|
||||||
|
currency: request.data.purchase_units[0].payments.captures[0].amount.currency_code,
|
||||||
|
subscriptionDuration: duration,
|
||||||
|
subscriptionDurationUnit: duration_unit,
|
||||||
|
subscriptionExpirationDate: updatedExpirationDate.toISOString(),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} catch(err) {
|
||||||
|
console.error('Failed to insert paypal payment!', err);
|
||||||
|
}
|
||||||
|
|
||||||
if (user.type === "corporate") {
|
if (user.type === "corporate") {
|
||||||
const snapshot = await getDocs(collection(db, "groups"));
|
const snapshot = await getDocs(collection(db, "groups"));
|
||||||
const groups: Group[] = (
|
const groups: Group[] = (
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const audioFile = files.audio;
|
const audioFile = files.audio;
|
||||||
const audioFileRef = ref(storage, `${fields.root}/${(audioFile as any).path.split("/").pop()!.replace("upload_", "")}`);
|
const audioFileRef = ref(storage, `${fields.root}/${(audioFile as any).path.replace("upload_", "")}`);
|
||||||
|
|
||||||
const binary = fs.readFileSync((audioFile as any).path).buffer;
|
const binary = fs.readFileSync((audioFile as any).path).buffer;
|
||||||
const snapshot = await uploadBytes(audioFileRef, binary);
|
const snapshot = await uploadBytes(audioFileRef, binary);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||||
import { sendEmail } from "@/email";
|
import { sendEmail } from "@/email";
|
||||||
import { app } from "@/firebase";
|
import { app } from "@/firebase";
|
||||||
import { Ticket, TicketTypeLabel } from "@/interfaces/ticket";
|
import { Ticket, TicketTypeLabel, TicketWithCorporate } from "@/interfaces/ticket";
|
||||||
import { sessionOptions } from "@/lib/session";
|
import { sessionOptions } from "@/lib/session";
|
||||||
import {
|
import {
|
||||||
collection,
|
collection,
|
||||||
@@ -9,11 +9,14 @@ import {
|
|||||||
getDocs,
|
getDocs,
|
||||||
getFirestore,
|
getFirestore,
|
||||||
setDoc,
|
setDoc,
|
||||||
|
where,
|
||||||
|
query,
|
||||||
} from "firebase/firestore";
|
} from "firebase/firestore";
|
||||||
import { withIronSessionApiRoute } from "iron-session/next";
|
import { withIronSessionApiRoute } from "iron-session/next";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
import ShortUniqueId from "short-unique-id";
|
import ShortUniqueId from "short-unique-id";
|
||||||
|
import { Group, CorporateUser } from "@/interfaces/user";
|
||||||
|
|
||||||
const db = getFirestore(app);
|
const db = getFirestore(app);
|
||||||
|
|
||||||
@@ -44,12 +47,38 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
async function get(req: NextApiRequest, res: NextApiResponse) {
|
async function get(req: NextApiRequest, res: NextApiResponse) {
|
||||||
const snapshot = await getDocs(collection(db, "tickets"));
|
const snapshot = await getDocs(collection(db, "tickets"));
|
||||||
|
|
||||||
res.status(200).json(
|
const docs = snapshot.docs.map((doc) => ({
|
||||||
snapshot.docs.map((doc) => ({
|
|
||||||
id: doc.id,
|
id: doc.id,
|
||||||
...doc.data(),
|
...doc.data(),
|
||||||
}))
|
})) as Ticket[];
|
||||||
);
|
|
||||||
|
// fetch all groups for these users
|
||||||
|
|
||||||
|
const reporters = [...new Set(docs.map((d) => d.reporter.id).filter((id) => id))];
|
||||||
|
|
||||||
|
const groupsSnapshot = await getDocs(query(collection(db, "groups"), where("participants", "array-contains-any", reporters)));
|
||||||
|
const groups = groupsSnapshot.docs.map((doc) => doc.data()) as Group[];
|
||||||
|
|
||||||
|
// based on the admin of each group, verify if it exists and it's of type corporate
|
||||||
|
const groupsAdmins = [...new Set(groups.map((g) => g.admin).filter((id) => id))];
|
||||||
|
const adminsSnapshot = await getDocs(query(collection(db, "users"), where("id", "in", groupsAdmins), where("type", "==", "corporate")));
|
||||||
|
const admins = adminsSnapshot.docs.map((doc) => doc.data());
|
||||||
|
|
||||||
|
const docsWithAdmins = docs.map((d) => {
|
||||||
|
const group = groups.find((g) => g.participants.includes(d.reporter.id));
|
||||||
|
const admin = admins.find((a) => a.id === group?.admin) as CorporateUser;
|
||||||
|
|
||||||
|
if(admin) {
|
||||||
|
return {
|
||||||
|
...d,
|
||||||
|
corporate: admin.corporateInformation?.companyInformation?.name,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return d;
|
||||||
|
}) as TicketWithCorporate[];
|
||||||
|
|
||||||
|
res.status(200).json(docsWithAdmins);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function post(req: NextApiRequest, res: NextApiResponse) {
|
async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ interface Contact {
|
|||||||
number: string;
|
number: string;
|
||||||
}
|
}
|
||||||
async function get(req: NextApiRequest, res: NextApiResponse) {
|
async function get(req: NextApiRequest, res: NextApiResponse) {
|
||||||
const { code } = req.query as { code: string };
|
const { code, language = 'en' } = req.query as { code: string, language: string};
|
||||||
|
|
||||||
const usersQuery = query(
|
const usersQuery = query(
|
||||||
collection(db, "users"),
|
collection(db, "users"),
|
||||||
@@ -43,9 +43,11 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
return newUser;
|
return newUser;
|
||||||
}) as Contact[];
|
}) as Contact[];
|
||||||
|
|
||||||
const country = countryCodes.findOne("countryCode" as any, code);
|
const country = countryCodes.findOne("countryCode" as any, code.toUpperCase());
|
||||||
|
const key = language === 'ar' ? 'countryNameLocal' : 'countryNameEn';
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
label: country.countryNameEn,
|
label: country[key],
|
||||||
entries,
|
entries,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ interface Contact {
|
|||||||
number: string;
|
number: string;
|
||||||
}
|
}
|
||||||
async function get(req: NextApiRequest, res: NextApiResponse) {
|
async function get(req: NextApiRequest, res: NextApiResponse) {
|
||||||
|
const { language = 'en' } = req.query as { language: string };
|
||||||
|
|
||||||
const usersQuery = query(
|
const usersQuery = query(
|
||||||
collection(db, "users"),
|
collection(db, "users"),
|
||||||
where("type", "==", "agent")
|
where("type", "==", "agent")
|
||||||
@@ -49,9 +51,10 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
) as Record<string, Contact[]>;
|
) as Record<string, Contact[]>;
|
||||||
|
|
||||||
const result = Object.keys(data).map((code) => {
|
const result = Object.keys(data).map((code) => {
|
||||||
const country = countryCodes.findOne("countryCode" as any, code);
|
const country = countryCodes.findOne("countryCode" as any, code.toUpperCase());
|
||||||
|
const key = language === 'ar' ? 'countryNameLocal' : 'countryNameEn';
|
||||||
return {
|
return {
|
||||||
label: country.countryNameEn,
|
label: country[key],
|
||||||
key: code,
|
key: code,
|
||||||
entries: data[code],
|
entries: data[code],
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -11,6 +11,7 @@ import {
|
|||||||
TicketStatusLabel,
|
TicketStatusLabel,
|
||||||
TicketType,
|
TicketType,
|
||||||
TicketTypeLabel,
|
TicketTypeLabel,
|
||||||
|
TicketWithCorporate,
|
||||||
} from "@/interfaces/ticket";
|
} from "@/interfaces/ticket";
|
||||||
import { sessionOptions } from "@/lib/session";
|
import { sessionOptions } from "@/lib/session";
|
||||||
import { shouldRedirectHome } from "@/utils/navigation.disabled";
|
import { shouldRedirectHome } from "@/utils/navigation.disabled";
|
||||||
@@ -28,7 +29,7 @@ import { useEffect, useState } from "react";
|
|||||||
import { BsArrowDown, BsArrowUp } from "react-icons/bs";
|
import { BsArrowDown, BsArrowUp } from "react-icons/bs";
|
||||||
import { ToastContainer } from "react-toastify";
|
import { ToastContainer } from "react-toastify";
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<Ticket>();
|
const columnHelper = createColumnHelper<TicketWithCorporate>();
|
||||||
|
|
||||||
export const getServerSideProps = withIronSessionSsr(({ req, res }) => {
|
export const getServerSideProps = withIronSessionSsr(({ req, res }) => {
|
||||||
const user = req.session.user;
|
const user = req.session.user;
|
||||||
@@ -75,10 +76,26 @@ const TypesClassNames: { [key in TicketType]: string } = {
|
|||||||
help: "bg-mti-blue-light",
|
help: "bg-mti-blue-light",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const escapedURL = process.env.NEXT_PUBLIC_WEBSITE_URL || ''.replace(
|
||||||
|
/[.*+?^${}()|[\]\\]/g,
|
||||||
|
"\\$&"
|
||||||
|
);
|
||||||
|
const fromHomepage = [new RegExp(`^${escapedURL}`), /\/contact$/];
|
||||||
|
|
||||||
|
type Source = "webpage" | "platform" | "";
|
||||||
|
|
||||||
|
const SOURCE_OPTIONS = [
|
||||||
|
{ value: "", label: "All" },
|
||||||
|
{ value: "webpage", label: "Webpage" },
|
||||||
|
{ value: "platform", label: "Platform" },
|
||||||
|
]
|
||||||
|
|
||||||
export default function Tickets() {
|
export default function Tickets() {
|
||||||
const [filteredTickets, setFilteredTickets] = useState<Ticket[]>([]);
|
const [filteredTickets, setFilteredTickets] = useState<Ticket[]>([]);
|
||||||
const [selectedTicket, setSelectedTicket] = useState<Ticket>();
|
const [selectedTicket, setSelectedTicket] = useState<Ticket>();
|
||||||
const [assigneeFilter, setAssigneeFilter] = useState<string>();
|
const [assigneeFilter, setAssigneeFilter] = useState<string>();
|
||||||
|
const [sourceFilter, setSourceFilter] = useState<Source>("");
|
||||||
|
|
||||||
const [dateSorting, setDateSorting] = useState<"asc" | "desc">("desc");
|
const [dateSorting, setDateSorting] = useState<"asc" | "desc">("desc");
|
||||||
|
|
||||||
const [typeFilter, setTypeFilter] = useState<TicketType>();
|
const [typeFilter, setTypeFilter] = useState<TicketType>();
|
||||||
@@ -90,7 +107,7 @@ export default function Tickets() {
|
|||||||
|
|
||||||
const sortByDate = (a: Ticket, b: Ticket) => {
|
const sortByDate = (a: Ticket, b: Ticket) => {
|
||||||
return moment((dateSorting === "desc" ? b : a).date).diff(
|
return moment((dateSorting === "desc" ? b : a).date).diff(
|
||||||
moment((dateSorting === "desc" ? a : b).date),
|
moment((dateSorting === "desc" ? a : b).date)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -102,11 +119,16 @@ export default function Tickets() {
|
|||||||
if (statusFilter) filters.push((x: Ticket) => x.status === statusFilter);
|
if (statusFilter) filters.push((x: Ticket) => x.status === statusFilter);
|
||||||
if (assigneeFilter)
|
if (assigneeFilter)
|
||||||
filters.push((x: Ticket) => x.assignedTo === assigneeFilter);
|
filters.push((x: Ticket) => x.assignedTo === assigneeFilter);
|
||||||
|
if (sourceFilter) {
|
||||||
|
if (sourceFilter === "webpage")
|
||||||
|
filters.push((x: Ticket) => fromHomepage.some((r) => r.test(x.reportedFrom)));
|
||||||
|
if (sourceFilter === "platform")
|
||||||
|
filters.push((x: Ticket) => !fromHomepage.some((r) => r.test(x.reportedFrom)));
|
||||||
|
}
|
||||||
setFilteredTickets(
|
setFilteredTickets(
|
||||||
[...filters.reduce((d, f) => d.filter(f), tickets)].sort(sortByDate),
|
[...filters.reduce((d, f) => d.filter(f), tickets)].sort(sortByDate)
|
||||||
);
|
);
|
||||||
}, [tickets, typeFilter, statusFilter, assigneeFilter, dateSorting, user]);
|
}, [tickets, typeFilter, statusFilter, assigneeFilter, dateSorting, user, sourceFilter]);
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
columnHelper.accessor("id", {
|
columnHelper.accessor("id", {
|
||||||
@@ -119,7 +141,7 @@ export default function Tickets() {
|
|||||||
<span
|
<span
|
||||||
className={clsx(
|
className={clsx(
|
||||||
"rounded-lg p-1 px-2 text-white",
|
"rounded-lg p-1 px-2 text-white",
|
||||||
TypesClassNames[info.getValue()],
|
TypesClassNames[info.getValue()]
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{TicketTypeLabel[info.getValue()]}
|
{TicketTypeLabel[info.getValue()]}
|
||||||
@@ -164,7 +186,7 @@ export default function Tickets() {
|
|||||||
<span
|
<span
|
||||||
className={clsx(
|
className={clsx(
|
||||||
"rounded-lg p-1 px-2 text-white",
|
"rounded-lg p-1 px-2 text-white",
|
||||||
StatusClassNames[info.getValue()],
|
StatusClassNames[info.getValue()]
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{TicketStatusLabel[info.getValue()]}
|
{TicketStatusLabel[info.getValue()]}
|
||||||
@@ -175,6 +197,10 @@ export default function Tickets() {
|
|||||||
header: "Assignee",
|
header: "Assignee",
|
||||||
cell: (info) => users.find((x) => x.id === info.getValue())?.name || "",
|
cell: (info) => users.find((x) => x.id === info.getValue())?.name || "",
|
||||||
}),
|
}),
|
||||||
|
columnHelper.accessor("corporate", {
|
||||||
|
header: "Corporate",
|
||||||
|
cell: (info) => info.getValue(),
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
const getAssigneeValue = () => {
|
const getAssigneeValue = () => {
|
||||||
@@ -290,7 +316,7 @@ export default function Tickets() {
|
|||||||
{ value: "me", label: "Assigned to me" },
|
{ value: "me", label: "Assigned to me" },
|
||||||
...users
|
...users
|
||||||
.filter((x) =>
|
.filter((x) =>
|
||||||
["admin", "developer", "agent"].includes(x.type),
|
["admin", "developer", "agent"].includes(x.type)
|
||||||
)
|
)
|
||||||
.map((u) => ({
|
.map((u) => ({
|
||||||
value: u.id,
|
value: u.id,
|
||||||
@@ -302,7 +328,7 @@ export default function Tickets() {
|
|||||||
onChange={(value) =>
|
onChange={(value) =>
|
||||||
value
|
value
|
||||||
? setAssigneeFilter(
|
? setAssigneeFilter(
|
||||||
value.value === "me" ? user.id : value.value,
|
value.value === "me" ? user.id : value.value
|
||||||
)
|
)
|
||||||
: setAssigneeFilter(undefined)
|
: setAssigneeFilter(undefined)
|
||||||
}
|
}
|
||||||
@@ -310,6 +336,18 @@ export default function Tickets() {
|
|||||||
isClearable
|
isClearable
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex w-full flex-col gap-3">
|
||||||
|
<label className="text-mti-gray-dim text-base font-normal">
|
||||||
|
Source
|
||||||
|
</label>
|
||||||
|
<Select
|
||||||
|
options={SOURCE_OPTIONS}
|
||||||
|
disabled={user.type === "agent"}
|
||||||
|
value={SOURCE_OPTIONS.find((x) => x.value === sourceFilter)}
|
||||||
|
onChange={(value) => setSourceFilter(value?.value as Source)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<table className="bg-mti-purple-ultralight/40 w-full rounded-xl">
|
<table className="bg-mti-purple-ultralight/40 w-full rounded-xl">
|
||||||
@@ -322,7 +360,7 @@ export default function Tickets() {
|
|||||||
? null
|
? null
|
||||||
: flexRender(
|
: flexRender(
|
||||||
header.column.columnDef.header,
|
header.column.columnDef.header,
|
||||||
header.getContext(),
|
header.getContext()
|
||||||
)}
|
)}
|
||||||
</th>
|
</th>
|
||||||
))}
|
))}
|
||||||
@@ -334,7 +372,7 @@ export default function Tickets() {
|
|||||||
<tr
|
<tr
|
||||||
className={clsx(
|
className={clsx(
|
||||||
"even:bg-mti-purple-ultralight/40 hover:bg-mti-purple-ultralight cursor-pointer rounded-lg py-2 odd:bg-white",
|
"even:bg-mti-purple-ultralight/40 hover:bg-mti-purple-ultralight cursor-pointer rounded-lg py-2 odd:bg-white",
|
||||||
"transition duration-300 ease-in-out",
|
"transition duration-300 ease-in-out"
|
||||||
)}
|
)}
|
||||||
onClick={() => setSelectedTicket(row.original)}
|
onClick={() => setSelectedTicket(row.original)}
|
||||||
key={row.id}
|
key={row.id}
|
||||||
@@ -343,7 +381,7 @@ export default function Tickets() {
|
|||||||
<td className="w-fit items-center px-4 py-2" key={cell.id}>
|
<td className="w-fit items-center px-4 py-2" key={cell.id}>
|
||||||
{flexRender(
|
{flexRender(
|
||||||
cell.column.columnDef.cell,
|
cell.column.columnDef.cell,
|
||||||
cell.getContext(),
|
cell.getContext()
|
||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
))}
|
))}
|
||||||
|
|||||||
Reference in New Issue
Block a user