Skip to content

Commit

Permalink
Merge pull request #1661 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
Dev Server
  • Loading branch information
nashnsulthan authored Oct 29, 2024
2 parents f561c87 + 0a70c83 commit 1aff022
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 32 deletions.
10 changes: 10 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import OrganizationSetting from "./modules/Dashboard/modules/Settings/pages/Orga
import SettingsHome from "./modules/Dashboard/modules/Settings/pages/Settings/SettingsHome";
import LcReportAttendee from "./modules/Dashboard/modules/LearningCircle/pages/LcDashboard/components/LcAttendeeReport";
import LcAdmin from "./modules/Dashboard/modules/LearningCircle/pages/LcAdmin/LcAdmin";
import VerifyOrganizations from "./modules/Dashboard/modules/VerifyOrganizations/VerifyOrganizations";

const Profile = lazy(
() => import("./modules/Dashboard/modules/Profile/pages/Profile")
Expand Down Expand Up @@ -376,6 +377,15 @@ function App() {
/>
)
},
{
path: "verify-organizations",
element: (
<AuthChecker
roles={[roles.ADMIN, roles.FELLOW]}
children={<VerifyOrganizations />}
/>
)
},
{
path: "campus-details",
element: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,11 @@
color: red;
font-size: small;
}

.skipButton {
color: var(--blue) !important;

&:hover {
color: #fff !important;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import { useLocation, useNavigate } from "react-router-dom";
import OnboardingTemplate from "../../../components/OnboardingTeamplate/OnboardingTemplate";
import OnboardingHeader from "../../../components/OnboardingHeader/OnboardingHeader";
import { Switch } from "@chakra-ui/react";
import { selectOrganization } from "../../../services/onboardingApis";
import {
createNewOrganization,
selectOrganization
} from "../../../services/onboardingApis";

const inputObject = {
organization: "Organization",
Expand Down Expand Up @@ -61,14 +64,18 @@ export default function CollegePage() {
id: "",
title: ""
});
const [organizationInput, setOrganizationInput] = useState("");
const [createOrganization, setCreateOrganization] = useState<{
title: string;
org_type: string;
} | null>(null);

const ruri = window.location.href.split("=")[1];

const CustomFilter = (
{ label, value }: { label: string; value: string },
string: string
): boolean => {
if (value === "Others") return true; // Always show "Others" option
if (!string) return true;
return label.toLowerCase().includes(string.toLowerCase());
};
Expand All @@ -88,6 +95,21 @@ export default function CollegePage() {
});
}, []);
const onSubmit = async (values: any) => {
if (createOrganization) {
createNewOrganization({
setIsLoading: setIsLoading,
org_data: createOrganization
}).then(res => {
if (res) {
if (ruri) {
navigate(`/${ruri}`);
} else {
navigate("/dashboard/connect-discord");
}
}
});
return;
}
selectOrganization({
setIsLoading: setIsLoading,
userData: {
Expand All @@ -113,6 +135,40 @@ export default function CollegePage() {
}
});
};
const getOptions = () => {
var orgs = isCollege ? colleges : companies;
var options: any[] = [];
orgs.forEach(org => {
options.push({ value: org.id, label: org.title });
});
if (
organizationInput &&
!options.some(opt => opt.label === organizationInput)
) {
options.push({
value: organizationInput,
label: `Create "${organizationInput}"`
});
}
return options;
};
const onOrgSelectChange = (e: any, formik: any) => {
if (
(isCollege ? colleges : companies).filter(val => val.id == e.value)
.length < 1
) {
setCreateOrganization({
title: e.value,
org_type: isCollege ? "College" : "Company"
});
formik.setFieldValue("organization", e.value);
return;
}
setCreateOrganization(null);
setSelectedOrganization(e);
formik.setFieldValue("organization", e.value);
inputObject.organization = e.value;
};
return (
<OnboardingTemplate>
<OnboardingHeader
Expand Down Expand Up @@ -144,41 +200,20 @@ export default function CollegePage() {
</div>
<div className={styles.inputBox}>
<ReactSelect
options={
[
{
value: "Others",
label: "Others"
},
...(isCollege
? colleges.map(college => ({
value: college.id,
label: college.title
}))
: companies.map(
company => ({
value: company.id,
label: company.title
})
))
] as any
}
onInputChange={e => {
setOrganizationInput(e);
}}
options={getOptions()}
name="organization"
placeholder={
isCollege
? "College"
: "Organization"
}
value={selectedOrganization.title}
filterOption={CustomFilter}
isDisabled={isloading}
onChange={(e: any) => {
setSelectedOrganization(e);
formik.setFieldValue(
"organization",
e.value
);
inputObject.organization = e.value;
onOrgSelectChange(e, formik);
}}
/>
</div>
Expand All @@ -188,7 +223,7 @@ export default function CollegePage() {
{formik.errors.college}
</span>
)}
{isCollege ? (
{isCollege && !createOrganization ? (
<>
<div className={styles.inputBox}>
<ReactSelect
Expand Down Expand Up @@ -265,7 +300,7 @@ export default function CollegePage() {

<div className={styles.submit}>
<PowerfulButton
style={{ color: "var(--blue)" }}
className={styles.skipButton}
variant="outline"
onClick={e => {
e.preventDefault();
Expand Down
25 changes: 25 additions & 0 deletions src/modules/Common/Authentication/services/onboardingApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,31 @@ export const getCommunities = ({
setIsLoading && setIsLoading(false);
};

export const createNewOrganization = async ({
setIsLoading,
org_data
}: {
setIsLoading: Dispatch<SetStateAction<boolean>>;
org_data: Object;
}) => {
try {
setIsLoading(true);
const res = await privateGateway.post(
"/api/v1/register/organization/create/",
org_data
);
if (res.status == 200 && !res.data.hasError) {
toast.success(res.data.message.general[0]);
return true;
} else {
toast.error("Organization selection failed.");
}
setIsLoading(false);
} catch (err: any) {
toast.error("Unable to select organization.");
}
return false;
};
export const selectOrganization = async ({
setIsLoading,
userData
Expand Down
6 changes: 6 additions & 0 deletions src/modules/Dashboard/layouts/DashboardRootLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ const DashboardRootLayout = (props: { component?: any }) => {
hasView: true,
roles: [roles.ADMIN]
},
{
url: "/dashboard/verify-organizations",
title: "Verify Organization",
hasView: true,
roles: [roles.ADMIN, roles.FELLOW]
},
{
url: "/dashboard/college-levels",
title: "College Levels",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ const LcReportAttendee = () => {
onChange={e => {
if (e.target.files) {
if (
e.target.files[0].size > 5000000
e.target.files[0].size > 2500000
) {
toast.error(
"File size should not exceed 5MB"
"File size should not exceed 2.5MB"
);
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { privateGateway } from "@/MuLearnServices/apiGateways";
import { organizationRoutes } from "@/MuLearnServices/urls";

export const getUnverifiedOrganizations = async (
setData: UseStateFunc<any>,
setIsLoading: UseStateFunc<boolean>
) => {
setIsLoading(true);
try {
const data = (
await privateGateway.get(
organizationRoutes.getUnverifiedOrganizations
)
).data.response;
setIsLoading(false);
setData(data);
} catch (err: unknown) {
setIsLoading(false);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import MuModal from "@/MuLearnComponents/MuModal/MuModal";
import Pagination from "@/MuLearnComponents/Pagination/Pagination";
import Table from "@/MuLearnComponents/Table/Table";
import THead from "@/MuLearnComponents/Table/THead";
import TableTop from "@/MuLearnComponents/TableTop/TableTop";
import { useEffect, useState } from "react";
import { Label } from "recharts";
import { getUnverifiedOrganizations } from "./VerifyOrganizationAPIs";

export default function VerifyOrganizations() {
const [data, setData] = useState<any[]>([]);
const [isLoading, setIsLoading] = useState(false);
const [isModalOpen, setIsModalOpen] = useState(false);
const [currentPage, setCurrentPage] = useState(1);
const [totalPages, setTotalPages] = useState(0);
const [perPage, setPerPage] = useState(20);
const columns = [
{ column: "title", Label: "Title", isSortable: false },
{ column: "org_type", Label: "Org Type", isSortable: false },
{ column: "created_by", Label: "Craeted By", isSortable: false },
{ column: "created_at", Label: "Created At", isSortable: false }
];
useEffect(() => {
getUnverifiedOrganizations(setData, setIsLoading);
}, []);

return (
<>
<MuModal
isOpen={isModalOpen}
onClose={() => setIsModalOpen(false)}
title={`Verify Organization`}
type={"success"}
onDone={() => {}}
>
Nothing
</MuModal>
{data && (
<>
<Table
rows={data}
isloading={isLoading}
page={currentPage}
perPage={perPage}
columnOrder={columns}
id={["id"]}
modalVerifyContent="Are you sure you want to verify this organization?"
modalVerifyHeading="Verify Organization"
// modalTypeContent="error"
// modalDeleteContent={`Are you sure you want to delete this organization?`}
// onDeleteClick={handleDelete}
>
<THead
columnOrder={columns}
onIconClick={() => {}}
action={false}
/>
<div></div>
</Table>
</>
)}
</>
);
}
1 change: 1 addition & 0 deletions src/services/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export const organizationRoutes = {
putUpdateOrganization: "/api/v1/dashboard/organisation/institutes/edit/",
deleteOrgnaization: "/api/v1/dashboard/organisation/institutes/delete/",
postGetInfo: "/api/v1/dashboard/organisation/institutes/info/",
getUnverifiedOrganizations: "/api/v1/dashboard/organisation/verify/list/",
getOrgCsv: (org_type: string) =>
`/api/v1/dashboard/organisation/institutes/${org_type}/csv/`,

Expand Down

0 comments on commit 1aff022

Please sign in to comment.