Skip to content

Commit

Permalink
Conponentize tipTap and UI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
melpsh committed Oct 4, 2024
1 parent ddd8f06 commit 1ccf232
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const DropDowns = () => {
/>

<DatePicker
label="Due Date:"
label="Due date:"
sx={inputStyles}
/>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,206 +1,73 @@
import { Box, Tooltip, Typography } from "@mui/material";
import { Box, Typography, Tooltip, IconButton } from "@mui/material";
import React, { useState } from "react";
import { useEditor, EditorContent } from "@tiptap/react";
import StarterKit from "@tiptap/starter-kit";
import {
FormatBold,
FormatItalic,
FormatListBulleted,
FormatListNumbered,
HMobiledata,
} from "@mui/icons-material";
import { IconButton } from "@mui/material";
import CloudUpload from "../../../assets/icons/cloudUpload.svg";
import RichTextEditor from "../../../components/RichTextEditor/index";

interface AuditorFeedbackProps {
activeSection: string;
}

const AuditorFeedback: React.FC<AuditorFeedbackProps> = React.memo(
({ activeSection }) => {
const [file, setFile] = useState<File | null>(null);
const [bulleted, setBulleted] = useState<boolean>(false);
const [numbered, setNumbered] = useState<boolean>(false);
const AuditorFeedback: React.FC<AuditorFeedbackProps> = ({ activeSection }) => {
const [file, setFile] = useState<File | null>(null);

const editor = useEditor({
extensions: [StarterKit],
content: "",
autofocus: true,
});
const handleFileUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.files && e.target.files[0]) {
setFile(e.target.files[0]);
}
};

const handleFileUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.files && e.target.files[0]) {
setFile(e.target.files[0]);
}
};
const UploadFile = () => {
document.getElementById("file-upload")?.click();
};

const applyFormatting = (type: string) => {
if (!editor) return;
const handleContentChange = (content: string) => {
console.log("Updated content: ", content);
};

switch (type) {
case "bold":
editor.chain().focus().toggleBold().run();
break;
case "italic":
editor.chain().focus().toggleItalic().run();
break;
case "uppercase":
const uppercaseText = editor.getText().toUpperCase();
editor.commands.setContent(uppercaseText);
break;
case "lowercase":
const lowercaseText = editor.getText().toLowerCase();
editor.commands.setContent(lowercaseText);
break;
case "bullets":
editor.chain().focus().toggleBulletList().run();
setBulleted(!bulleted);
setNumbered(false);
break;
case "numbers":
editor.chain().focus().toggleOrderedList().run();
setNumbered(!numbered);
setBulleted(false);
break;
default:
break;
}
};
return (
<Box sx={{ width: "100%", padding: 2 }}>
<Typography sx={{ mb: 2 }}>
{activeSection === "Evidence" ? "Evidence:" : "Auditor Feedback:"}
</Typography>

const UploadFile = () => {
document.getElementById("file-upload")?.click();
};
{/* Use the RichTextEditor component */}
<RichTextEditor onContentChange={handleContentChange} />

return (
<Box sx={{ width: "100%", padding: 2 }}>
<Typography sx={{ mb: 2 }}>
{activeSection === "Evidence" ? "Evidence:" : "Auditor Feedback:"}
{/* File Upload */}
<Box
sx={{
display: "flex",
flexDirection: "row-reverse",
border: "1px dotted",
borderColor: "#D0D5DD",
width: 472,
alignItems: "center",
cursor: "pointer",
}}
onClick={UploadFile}
>
<Typography sx={{ color: "black", padding: 5, marginLeft: 1, paddingLeft: 0 }}>
You can also drag and drop, or click to upload a feedback.
</Typography>

{/* Toolbar */}
<Box
sx={{
display: "flex",
border: "1px solid",
borderColor: "#c4c4c4",
borderBottom: "none",
}}
>
<Tooltip title="Bold">
<IconButton onClick={() => applyFormatting("bold")} disableRipple>
<FormatBold />
</IconButton>
</Tooltip>
<Tooltip title="Italic">
<IconButton onClick={() => applyFormatting("italic")} disableRipple>
<FormatItalic />
</IconButton>
</Tooltip>
<Tooltip title="Uppercase">
<IconButton
onClick={() => applyFormatting("uppercase")}
disableRipple
>
<HMobiledata sx={{ fontSize: "30px", fontWeight: "bold" }} />
</IconButton>
</Tooltip>
<Tooltip title="Lowercase">
<IconButton
onClick={() => applyFormatting("lowercase")}
disableRipple
>
<HMobiledata />
</IconButton>
</Tooltip>
<Tooltip title="Bullets">
<IconButton
onClick={() => applyFormatting("bullets")}
disableRipple
color={bulleted ? "primary" : "default"}
>
<FormatListBulleted />
</IconButton>
</Tooltip>
<Tooltip title="Numbers">
<IconButton
onClick={() => applyFormatting("numbers")}
disableRipple
color={numbered ? "primary" : "default"}
>
<FormatListNumbered />
</IconButton>
</Tooltip>
</Box>

<Box>
<EditorContent
editor={editor}
style={{
border: "1px solid #c4c4c4",
minHeight: "110px",
maxHeight: "110px",
overflowY: 'auto',
padding: "8px",
borderTop: "none",
outline: "none",
marginBottom: "10px",
}}
/>
</Box>
<style>
{`
.ProseMirror {
border: none !important;
outline: none !important;
box-shadow: none !important;
white-space: pre-wrap;
}
`}
</style>

{/* File Upload */}
<Box
sx={{
display: "flex",
flexDirection: "row-reverse",
border: "1px dotted",
borderColor: "#D0D5DD",
width: 472,
alignItems: "center",
cursor: "pointer",
}}
onClick={UploadFile}
>
<Typography
sx={{ color: "black", padding: 5, marginLeft: 1, paddingLeft: 0 }}
>
You can also drag and drop, or click to upload a feedback.
</Typography>
<Tooltip title="Attach a file">
<IconButton component="label">
<img
src={CloudUpload}
alt="Upload"
style={{ height: 19, width: 20 }}
/>
<input
type="file"
hidden
id="file-upload"
onChange={handleFileUpload}
/>
</IconButton>
</Tooltip>
</Box>

{file && (
<Typography variant="body2" sx={{ mt: 2 }}>
Attached file: {file.name}
</Typography>
)}
<Tooltip title="Attach a file">
<IconButton component="label">
<img
src={CloudUpload}
alt="Upload"
style={{ height: 19, width: 20 }}
/>
<input type="file" hidden id="file-upload" onChange={handleFileUpload} />
</IconButton>
</Tooltip>
</Box>
);
}
);

{file && (
<Typography variant="body2" sx={{ mt: 2 }}>
Attached file: {file.name}
</Typography>
)}
</Box>
);
};

export default AuditorFeedback;
38 changes: 29 additions & 9 deletions Clients/src/presentation/components/Modals/Controlpane/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
Box,
Tabs,
Tab,
IconButton,
} from "@mui/material";
import CloseIcon from '@mui/icons-material/Close';

import React, { useState } from "react";
import DropDowns from "../../Inputs/Dropdowns";
Expand All @@ -28,10 +30,16 @@ const CustomModal: React.FC<CustomModalProps> = ({
title,
}) => {
const theme = useTheme();
// State for the date input
const [selectedTab, setSelectedTab] = useState<number>(0);
const [activeSection, setActiveSection] = useState<string>("Overview");

const extractNumberFromTitle = (title: string) => {
const match = title.match(/\d+/);
return match ? match[0] : "0";
};

const titleNumber = extractNumberFromTitle(title);

const handleClose = () => setIsOpen(false);

const handleSelectedTab = (event: React.SyntheticEvent, newValue: number) => {
Expand Down Expand Up @@ -91,6 +99,18 @@ const CustomModal: React.FC<CustomModalProps> = ({
},
}}
>
<IconButton
onClick={handleClose}
sx={{
position: "absolute",
top: theme.spacing(2),
right: theme.spacing(2),
}}
disableRipple
>
<CloseIcon />
</IconButton>

<Typography fontSize={16} fontWeight={600} sx={{ textAlign: "left" }}>
{title}
</Typography>
Expand All @@ -100,7 +120,7 @@ const CustomModal: React.FC<CustomModalProps> = ({
throughout the entire lifecycle of the high-risk AI system.
</Typography>
<DropDowns />
<Divider sx={{ borderColor: "#C2C2C2", mt: 3 }} />
<Divider sx={{ borderColor: "#C2C2C2", mt: theme.spacing(3) }} />

<Box sx={{ width: "100%", bgcolor: "background.paper" }}>
<Tabs
Expand All @@ -110,10 +130,10 @@ const CustomModal: React.FC<CustomModalProps> = ({
textColor="primary"
sx={{ justifyContent: "flex-start" }}
>
<Tab label="Subcontrol 1" sx={{ textTransform: "none" }} />
<Tab label="Subcontrol 2" sx={{ textTransform: "none" }} />
<Tab label="Subcontrol 3" sx={{ textTransform: "none" }} />
<Tab label="Subcontrol 4" sx={{ textTransform: "none" }} />
<Tab label="Subcontrol 1" sx={{ textTransform: "none" }} disableRipple />
<Tab label="Subcontrol 2" sx={{ textTransform: "none" }} disableRipple />
<Tab label="Subcontrol 3" sx={{ textTransform: "none" }} disableRipple />
<Tab label="Subcontrol 4" sx={{ textTransform: "none" }} disableRipple />
</Tabs>
</Box>

Expand Down Expand Up @@ -168,11 +188,11 @@ const CustomModal: React.FC<CustomModalProps> = ({
fontWeight={600}
sx={{ textAlign: "left", mb: 3 }}
>
Subcontrol 19.1
Subcontrol {titleNumber}.{selectedTab + 1}
</Typography>
<Typography variant="body1" sx={{ mb: 5 }}>
Plan and execute the risk management process as a continuous
iterative cycle. (EU AI ACT Ref: Subcontrol 19.1)
iterative cycle. (EU AI ACT Ref: Subcontrol {titleNumber}.{selectedTab + 1})
</Typography>
{activeSection === "Overview" && (
<Typography variant="body1">
Expand All @@ -183,7 +203,7 @@ const CustomModal: React.FC<CustomModalProps> = ({
<AuditorFeedback activeSection={activeSection} />
)}
</Box>
<Box sx={{ display: "flex", justifyContent: "space-between", mt: 2}}>
<Box sx={{ display: "flex", justifyContent: "space-between", mt: 2 }}>
<Stack
gap={theme.spacing(4)}
sx={{ display: "flex", flexDirection: "row" }}
Expand Down
Loading

0 comments on commit 1ccf232

Please sign in to comment.