Updated the code to name the field companyArabName and made it so it returns it when arabic
This commit is contained in:
@@ -106,7 +106,7 @@ const UserCard = ({
|
|||||||
: undefined,
|
: undefined,
|
||||||
);
|
);
|
||||||
const [arabName, setArabName] = useState(
|
const [arabName, setArabName] = useState(
|
||||||
user.type === "agent" ? user.agentInformation?.arabName : undefined,
|
user.type === "agent" ? user.agentInformation?.companyArabName : undefined,
|
||||||
);
|
);
|
||||||
const [commercialRegistration, setCommercialRegistration] = useState(
|
const [commercialRegistration, setCommercialRegistration] = useState(
|
||||||
user.type === "agent"
|
user.type === "agent"
|
||||||
@@ -236,21 +236,21 @@ const UserCard = ({
|
|||||||
<>
|
<>
|
||||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-8 w-full">
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-8 w-full">
|
||||||
<Input
|
<Input
|
||||||
label="Arab Name"
|
label="Company Name (Arabic)"
|
||||||
type="text"
|
type="text"
|
||||||
name="arabName"
|
name="arabName"
|
||||||
onChange={setArabName}
|
onChange={setArabName}
|
||||||
placeholder="Enter their arab name"
|
placeholder="Enter their company's name in arabic"
|
||||||
defaultValue={arabName}
|
defaultValue={arabName}
|
||||||
required
|
required
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label="Company Name"
|
label="Company Name (English)"
|
||||||
type="text"
|
type="text"
|
||||||
name="companyName"
|
name="companyName"
|
||||||
onChange={setCompanyName}
|
onChange={setCompanyName}
|
||||||
placeholder="Enter their company's name"
|
placeholder="Enter their company's name in english"
|
||||||
defaultValue={companyName}
|
defaultValue={companyName}
|
||||||
required
|
required
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export interface CorporateInformation {
|
|||||||
export interface AgentInformation {
|
export interface AgentInformation {
|
||||||
companyName: string;
|
companyName: string;
|
||||||
commercialRegistration: string;
|
commercialRegistration: string;
|
||||||
arabName?: string;
|
companyArabName?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CompanyInformation {
|
export interface CompanyInformation {
|
||||||
|
|||||||
@@ -23,12 +23,15 @@ interface Contact {
|
|||||||
number: string;
|
number: string;
|
||||||
}
|
}
|
||||||
async function get(req: NextApiRequest, res: NextApiResponse) {
|
async function get(req: NextApiRequest, res: NextApiResponse) {
|
||||||
const { code, language = 'en' } = req.query as { code: string, language: string};
|
const { code, language = "en" } = req.query as {
|
||||||
|
code: string;
|
||||||
|
language: string;
|
||||||
|
};
|
||||||
|
|
||||||
const usersQuery = query(
|
const usersQuery = query(
|
||||||
collection(db, "users"),
|
collection(db, "users"),
|
||||||
where("type", "==", "agent"),
|
where("type", "==", "agent"),
|
||||||
where("demographicInformation.country", "==", code)
|
where("demographicInformation.country", "==", code),
|
||||||
);
|
);
|
||||||
const docsUser = await getDocs(usersQuery);
|
const docsUser = await getDocs(usersQuery);
|
||||||
|
|
||||||
@@ -36,15 +39,22 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
|
|
||||||
const entries = docs.map((user: AgentUser) => {
|
const entries = docs.map((user: AgentUser) => {
|
||||||
const newUser = {
|
const newUser = {
|
||||||
name: user.agentInformation.companyName,
|
name:
|
||||||
|
(language === "en"
|
||||||
|
? user.agentInformation?.companyName
|
||||||
|
: user.agentInformation?.companyArabName ||
|
||||||
|
user.agentInformation?.companyName) || user.name,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
number: user.demographicInformation?.phone as string,
|
number: user.demographicInformation?.phone as string,
|
||||||
} as Contact;
|
} as Contact;
|
||||||
return newUser;
|
return newUser;
|
||||||
}) as Contact[];
|
}) as Contact[];
|
||||||
|
|
||||||
const country = countryCodes.findOne("countryCode" as any, code.toUpperCase());
|
const country = countryCodes.findOne(
|
||||||
const key = language === 'ar' ? 'countryNameLocal' : 'countryNameEn';
|
"countryCode" as any,
|
||||||
|
code.toUpperCase(),
|
||||||
|
);
|
||||||
|
const key = language === "ar" ? "countryNameLocal" : "countryNameEn";
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
label: country[key],
|
label: country[key],
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
import {app, adminApp} from "@/firebase";
|
import { app, adminApp } from "@/firebase";
|
||||||
import {AgentUser} from "@/interfaces/user";
|
import { AgentUser } from "@/interfaces/user";
|
||||||
import {sessionOptions} from "@/lib/session";
|
import { sessionOptions } from "@/lib/session";
|
||||||
import {collection, getDocs, getFirestore, query, where} from "firebase/firestore";
|
import {
|
||||||
import {getAuth} from "firebase-admin/auth";
|
collection,
|
||||||
import {withIronSessionApiRoute} from "iron-session/next";
|
getDocs,
|
||||||
import {NextApiRequest, NextApiResponse} from "next";
|
getFirestore,
|
||||||
|
query,
|
||||||
|
where,
|
||||||
|
} from "firebase/firestore";
|
||||||
|
import { getAuth } from "firebase-admin/auth";
|
||||||
|
import { withIronSessionApiRoute } from "iron-session/next";
|
||||||
|
import { NextApiRequest, NextApiResponse } from "next";
|
||||||
import countryCodes from "country-codes-list";
|
import countryCodes from "country-codes-list";
|
||||||
const db = getFirestore(app);
|
const db = getFirestore(app);
|
||||||
const auth = getAuth(adminApp);
|
const auth = getAuth(adminApp);
|
||||||
@@ -17,18 +23,26 @@ 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 { language = "en" } = req.query as { language: string };
|
||||||
|
|
||||||
const usersQuery = query(collection(db, "users"), where("type", "==", "agent"));
|
const usersQuery = query(
|
||||||
|
collection(db, "users"),
|
||||||
|
where("type", "==", "agent"),
|
||||||
|
);
|
||||||
const docsUser = await getDocs(usersQuery);
|
const docsUser = await getDocs(usersQuery);
|
||||||
|
|
||||||
const docs = docsUser.docs.map((doc) => doc.data() as AgentUser);
|
const docs = docsUser.docs.map((doc) => doc.data() as AgentUser);
|
||||||
|
|
||||||
const data = docs.reduce((acc: Record<string, Contact[]>, user: AgentUser) => {
|
const data = docs.reduce(
|
||||||
|
(acc: Record<string, Contact[]>, user: AgentUser) => {
|
||||||
const countryCode = user.demographicInformation?.country as string;
|
const countryCode = user.demographicInformation?.country as string;
|
||||||
const currentValues = acc[countryCode] || ([] as Contact[]);
|
const currentValues = acc[countryCode] || ([] as Contact[]);
|
||||||
const newUser = {
|
const newUser = {
|
||||||
name: user.agentInformation?.companyName || user.name,
|
name:
|
||||||
|
(language === "en"
|
||||||
|
? user.agentInformation?.companyName
|
||||||
|
: user.agentInformation?.companyArabName ||
|
||||||
|
user.agentInformation?.companyName) || user.name,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
number: user.demographicInformation?.phone as string,
|
number: user.demographicInformation?.phone as string,
|
||||||
} as Contact;
|
} as Contact;
|
||||||
@@ -36,10 +50,15 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
...acc,
|
...acc,
|
||||||
[countryCode]: [...currentValues, newUser],
|
[countryCode]: [...currentValues, newUser],
|
||||||
};
|
};
|
||||||
}, {}) 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.toUpperCase());
|
const country = countryCodes.findOne(
|
||||||
|
"countryCode" as any,
|
||||||
|
code.toUpperCase(),
|
||||||
|
);
|
||||||
if (!country) return null;
|
if (!country) return null;
|
||||||
const key = language === "ar" ? "countryNameLocal" : "countryNameEn";
|
const key = language === "ar" ? "countryNameLocal" : "countryNameEn";
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
: undefined,
|
: undefined,
|
||||||
);
|
);
|
||||||
const [arabName, setArabName] = useState<string | undefined>(
|
const [arabName, setArabName] = useState<string | undefined>(
|
||||||
user.type === "agent" ? user.agentInformation?.arabName : undefined,
|
user.type === "agent" ? user.agentInformation?.companyArabName : undefined,
|
||||||
);
|
);
|
||||||
|
|
||||||
const [timezone, setTimezone] = useState<string>(
|
const [timezone, setTimezone] = useState<string>(
|
||||||
|
|||||||
Reference in New Issue
Block a user