import React, { useEffect } from "react"; import theme from "../theme.jsx"; import { makeStyles } from "@mui/styles"; import { toast } from 'react-toastify'; import { Tooltip, Grid, Button, TextField, Typography, IconButton, } from "@mui/material"; import { ExpandLess as ExpandLessIcon, ExpandMore as ExpandMoreIcon, Save as SaveIcon, } from "@mui/icons-material"; const useStyles = makeStyles({ notchedOutline: { borderColor: "#f85a3e !important", }, }); const defaultImage = theme.palette.defaultImage const OrgHeader = (props) => { const { userdata, selectedOrganization, setSelectedOrganization, globalUrl, isCloud, adminTab, handleEditOrg, } = props; const classes = useStyles(); var upload = ""; const defaultBranch = "master"; const [orgName, setOrgName] = React.useState(selectedOrganization.name); const [orgDescription, setOrgDescription] = React.useState( selectedOrganization.description ); const [file, setFile] = React.useState(""); const [fileBase64, setFileBase64] = React.useState( selectedOrganization.image ); const [expanded, setExpanded] = React.useState(false); if (file !== "") { const img = document.getElementById("logo"); var canvas = document.createElement("canvas"); canvas.width = 174; canvas.height = 174; var ctx = canvas.getContext("2d"); img.onload = function () { // img, x, y, width, height //ctx.drawImage(img, 174, 174) //console.log("IMG natural: ", img.naturalWidth, img.naturalHeight) //ctx.drawImage(img, 0, 0, 174, 174) ctx.drawImage( img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height ); const canvasUrl = canvas.toDataURL(); if (canvasUrl !== fileBase64) { setFileBase64(canvasUrl); selectedOrganization.image = canvasUrl; setSelectedOrganization(selectedOrganization); } }; } var image = ""; const editHeaderImage = (event) => { const file = event.target.value; const actualFile = event.target.files[0]; const fileObject = URL.createObjectURL(actualFile); setFile(fileObject); }; //console.log("USER: ", userdata) const orgSaveButton = ( ); var imageData = file.length > 0 ? file : fileBase64; imageData = imageData === undefined || imageData.length === 0 ? defaultImage : imageData const imageInfo = ( ); return (
0 ? null : "1px solid #f85a3e", cursor: "pointer", maxWidth: 174, maxHeight: 174, borderRadius: theme.shape.borderRadius, }} onClick={() => { upload.click(); }} > (upload = ref)} onChange={editHeaderImage} /> {imageInfo}
Name { const invalid = ["#", ":", "."]; for (var key in invalid) { if (e.target.value.includes(invalid[key])) { toast("Can't use " + invalid[key] + " in name"); return; } } if (e.target.value.length > 100) { toast("Choose a shorter name."); return; } setOrgName(e.target.value); }} color="primary" InputProps={{ style: { color: "white", height: "50px", fontSize: "1em", }, classes: { notchedOutline: classes.notchedOutline, }, }} />
Description
{ setOrgDescription(e.target.value); }} InputProps={{ classes: { notchedOutline: classes.notchedOutline, }, style: { color: "white", }, }} />
{orgSaveButton}
); }; export default OrgHeader;