Skip to content
Snippets Groups Projects
Commit 1236de73 authored by Planoetscher Daniel (Student Com20)'s avatar Planoetscher Daniel (Student Com20)
Browse files

bugfixes

parent 7bcaca2d
No related branches found
No related tags found
No related merge requests found
......@@ -92,7 +92,7 @@ interface NewProjectData {
name: string;
text: string;
color: string;
deadline?: Date;
deadline?: string;
}
export function createProject(project: NewProjectData): Promise<string> {
......
......@@ -9,7 +9,7 @@ import CheckboxGroup from 'components/ui/CheckboxGroup';
interface Props {
project?: Project
onSubmit: (teams: string[], name: string, text: string, color: string, status?: Status, deadline?: Date) => void;
onSubmit: (teams: string[], name: string, text: string, color: string, status?: Status, deadline?: string) => void;
}
function validateName(name: string): string | null {
......@@ -44,22 +44,42 @@ function validateTeams(teams: string[]): string | null {
}
}
//TODO add to ryoko-moment something like that
export function getDateString(date?: Date) {
if (date) {
let month = date.getMonth() + 1;
return date.getFullYear() + '-'
+ (month / 10 < 1 ? '0' + month : month) + '-'
+ (date.getDate() / 10 < 1 ? '0' + date.getDate() : date.getDate());
} else {
return undefined;
}
}
export default function ProjectForm({ project, onSubmit }: Props) {
const [name, setName] = useState(project?.name);
const [text, setText] = useState(project?.text);
const [status, setStatus] = useState(project?.status);
const [color, setColor] = useState(project?.color);
const [deadline, setDeadline] = useState(project?.deadline);
const [deadline, setDeadline] = useState(getDateString(project?.deadline));
const [error, setError] = useState('');
const [teams, setTeams] = useState(project?.teams ?? []);
const [allTeams, setAllTeams] = useState<Team[]>([]);
useEffect(() => {
//TODO refactor
teams.forEach((userTeam) => {
getTeam(userTeam).then((team) => {
setAllTeams(state => [...state, team]);
setAllTeams(state => {
if (!state.find((t) => t.id === team.id)) {
return [...state, team];
}
return [...state];
});
});
});
getTeams().then((allTeamsItems) => {
......@@ -68,13 +88,13 @@ export default function ProjectForm({ project, onSubmit }: Props) {
if (!state.find((team) => team.id === allTeamsItem.id)) {
return [...state, allTeamsItem];
}
return [...state];
});
})
});
}, [teams])
const colors = Object.values(ProjectColors);
const allStatus = Object.values(Status);
......@@ -86,6 +106,7 @@ export default function ProjectForm({ project, onSubmit }: Props) {
validateColor(color ?? '') === null &&
validateTeams(teams) === null
) {
onSubmit?.(teams, name ?? '', text ?? '', color ?? '', status ?? Status.OPEN, deadline);
} else {
setError('Please fill in the mandatory fields.');
......@@ -128,7 +149,7 @@ export default function ProjectForm({ project, onSubmit }: Props) {
<TextInput
label="Deadline"
name="text"
defaultText={project?.deadline?.toString()}
defaultText={deadline}
onChange={setDeadline}
type="date"
/>
......@@ -139,14 +160,15 @@ export default function ProjectForm({ project, onSubmit }: Props) {
{
status &&
<select onChange={(e) => {
let currentStatus = Object.values(Status).find(s => s === e.target.value) ?? Status.OPEN;
<select defaultValue={project?.status} onChange={(e) => {
let currentStatus = Object.values(Status).find(s => s === e.target.value) ?? undefined;
setStatus(currentStatus);
}
}>
<option value="">Please choose a status</option>
{
allStatus.map((s) => (
<option selected={status === s} value={s} key={s}>{s}</option>
<option value={s} key={s}>{s}</option>
))
}
</select>
......
......@@ -15,7 +15,7 @@ export default function CheckboxGroup({ choices, chosen, setChosen }: Props) {
<div className="team-item" key={choice.id}>
<input type="checkbox" id={choice.id}
checked={chosen.indexOf(choice.id) >= 0}
onClick={(e) => {
onChange={(e) => {
if (chosen.find(id => choice.id === id)) {
setChosen((state: any) => state.filter((id: any) => id !== choice.id));
} else {
......
import { ChangeEvent, FocusEvent, useCallback, useState } from "react";
import './text-input.scss';
interface Props {
......@@ -17,12 +16,8 @@ export default function TextInput({ label, name, type, onChange, validation, com
const [error, setError] = useState('');
const handleChange = useCallback((e: ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => {
if (type === 'date') {
onChange(new Date(e.target.value));
} else {
onChange(e.target.value);
}
}, [onChange, type]);
onChange(e.target.value);
}, [onChange]);
const handleBlur = useCallback(async (e: FocusEvent<HTMLTextAreaElement | HTMLInputElement>) => {
let error = await validation?.(e.target.value, compareValue ?? '');
......
......@@ -7,7 +7,7 @@ import Callout from 'components/ui/Callout';
export default function ProjectCreate() {
const history = useHistory();
const [error, setError] = useState('');
const handleSubmit = useCallback(async (teams: string[], name: string, text: string, color: string, status?: Status, deadline?: Date) => {
const handleSubmit = useCallback(async (teams: string[], name: string, text: string, color: string, status?: Status, deadline?: string) => {
try {
if (await createProject({ teams, name, text, color, deadline })) {
history.push('/projects');
......@@ -17,7 +17,6 @@ export default function ProjectCreate() {
} catch (e) { }
}, [history]);
return (
<div className="project-create-page">
<div className="content-container">
......
......@@ -22,7 +22,7 @@ export default function ProjectEdit() {
});
}, [history, projectId]);
const handleSubmit = useCallback(async (teams: string[], name: string, text: string, color: string, status?: Status, deadline?: Date) => {
const handleSubmit = useCallback(async (teams: string[], name: string, text: string, color: string, status?: Status, deadline?: string) => {
try {
if (project) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment