Skip to content

Commit

Permalink
feat:fixed iframe delete bt
Browse files Browse the repository at this point in the history
  • Loading branch information
NishantGupt786 committed Oct 2, 2024
1 parent 0e62f1f commit 70c6c68
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
24 changes: 14 additions & 10 deletions src/app/adminupload/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -486,21 +486,25 @@ const Upload: React.FC = () => {
{typeof asset !== "string" &&
typeof asset?.url === "string" &&
asset.url.toLowerCase().endsWith(".pdf") ? (
<div className="relative h-full hover:brightness-50">
<iframe
src={asset.url}
className="h-full w-full"
title={`Uploaded PDF ${index + 1}`}
/>
<div className="absolute inset-0 flex items-center justify-center">
<div className="h-full">
<div
className="mb-4 flex cursor-pointer gap-x-4"
onClick={() =>
handleDelete(asset.public_id, asset.type, asset.url)
}
>
<Trash
color="#ed333b"
className="z-[100] cursor-pointer hover:brightness-200"
onClick={() =>
handleDelete(asset.public_id, asset.type, asset.url)
}
/>
<span>Delete PDF</span>
</div>

<iframe
src={asset.url}
className="h-full w-full"
title={`Uploaded PDF ${index + 1}`}
/>
</div>
) : (
<div className="relative h-72 w-full">
Expand Down
17 changes: 10 additions & 7 deletions src/app/papersadminlogin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import { useState } from "react";
import axios, { type AxiosError } from "axios";
import { useRouter } from "next/navigation";
import { type LoginResponse, type ErrorResponse } from "@/interface";
import { type LoginResponse, type ErrorResponse, type DecryptedLoginResponse } from "@/interface";
import Cryptr from "cryptr";

const cryptr = new Cryptr(
process.env.NEXT_PUBLIC_CRYPTO_SECRET || "default_crypto_secret",
process.env.NEXT_PUBLIC_CRYPTO_SECRET ?? "default_crypto_secret",
);

const LoginPage = () => {
Expand All @@ -24,11 +24,14 @@ const LoginPage = () => {

const { res } = response.data;
const decryptedToken = cryptr.decrypt(res);
const message = JSON.parse(decryptedToken);
const token = message.token;
console.log("Decrypted token:", token);
localStorage.setItem("token", token);
router.push("/adminupload");
try {
const message = JSON.parse(decryptedToken) as DecryptedLoginResponse;
const token = message.token;
localStorage.setItem("token", token);
router.push("/adminupload");
} catch (error) {
console.error("Failed to parse decrypted token", error);
}
} catch (error) {
if (axios.isAxiosError(error)) {
const axiosError = error as AxiosError<ErrorResponse>;
Expand Down
8 changes: 4 additions & 4 deletions src/app/upload/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { slots, courses } from "./select_options";
import toast, { Toaster } from "react-hot-toast";
import { handleAPIError } from "../util/error";
import { useRouter } from "next/navigation";
import { ApiError } from "next/dist/server/api-utils";
import { type ApiError } from "next/dist/server/api-utils";

const Page = () => {
const router = useRouter();
Expand Down Expand Up @@ -102,7 +102,7 @@ const Page = () => {
className="m-2 rounded-md border p-2"
>
{slots.map((slot) => {
return <option value={slot}>{slot}</option>;
return <option key={slot} value={slot}>{slot}</option>;
})}
</select>
</label>
Expand Down Expand Up @@ -131,7 +131,7 @@ const Page = () => {
className="m-2 rounded-md border p-2"
>
{courses.map((course) => (
<option value={course}>{course}</option>
<option key={course} value={course}>{course}</option>
))}
</select>
</label>
Expand Down Expand Up @@ -171,7 +171,7 @@ const Page = () => {
ref={fileInputRef}
className="hidden"
onChange={(e) => {
const filesArray = Array.from(e.target.files || []);
const filesArray = Array.from(e.target.files ?? []);
setFiles(filesArray);
}}
/>
Expand Down
8 changes: 8 additions & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,12 @@ export interface ErrorResponse {
export interface LoginRequest {
email: string;
password: string;
}

export interface DecryptedLoginResponse{
token: string;
user:{
email: string;
id: string;
}
}

0 comments on commit 70c6c68

Please sign in to comment.