Created the Name.jsx settings component
This commit is contained in:
parent
12700b6301
commit
3a4369b40d
@ -0,0 +1,48 @@
|
|||||||
|
import {Box, Button, IconButton, TextField, Typography} from "@mui/material";
|
||||||
|
import {CopyAll, Save} from "@mui/icons-material";
|
||||||
|
import {useContext, useState} from "react";
|
||||||
|
import {ProjectContext} from "@/states/Dashboard/contexts/Project";
|
||||||
|
import {patchRequest} from "@/common/utils/RequestUtil.js";
|
||||||
|
|
||||||
|
export const Name = () => {
|
||||||
|
const {currentProject, updateProjects} = useContext(ProjectContext);
|
||||||
|
|
||||||
|
const [name, setName] = useState(currentProject.name);
|
||||||
|
const [nameChanged, setNameChanged] = useState(false);
|
||||||
|
|
||||||
|
const updateName = (event) => {
|
||||||
|
setName(event.target.value);
|
||||||
|
setNameChanged(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
const copyName = () => {
|
||||||
|
navigator.clipboard.writeText(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
const saveName = async () => {
|
||||||
|
try {
|
||||||
|
await patchRequest(`/project/${currentProject.id}`, {name});
|
||||||
|
await updateProjects();
|
||||||
|
setNameChanged(false);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box sx={{border: 1, borderColor: 'divider', borderRadius: 1.5, p: 2.5, width: {xs: "100%", lg: "33%"}}}>
|
||||||
|
<Typography variant="h5" fontWeight={700}>Projektname</Typography>
|
||||||
|
<Typography variant="body1" color="text.secondary" fontWeight={500}>
|
||||||
|
Dies ist der Projektname. Du findest diesen über
|
||||||
|
das Dashboard verteilt überall und er hilft dir, dein
|
||||||
|
Projekt zu identifizieren
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<TextField sx={{mt: 1.5}} variant="outlined" fullWidth value={name} onChange={updateName} size="small"
|
||||||
|
InputProps={nameChanged ? {endAdornment: <IconButton onClick={saveName}><Save/></IconButton>} : {}}/>
|
||||||
|
|
||||||
|
<Button variant="contained" color="primary" startIcon={<CopyAll/>} sx={{mt: 1.5}}
|
||||||
|
onClick={copyName}>Kopieren</Button>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user