Skip to content

Commit

Permalink
feat: Aseta suunnittelusopimustiedot tallentumaan projektin tiedot -l…
Browse files Browse the repository at this point in the history
…omakkeella

* feat: Aseta suunnittelusopimustiedot tallentumaan projektin tiedot -lomakkeella

* laita adaptSuunnitteluSopimusToSave palauttamaan null arvon, kun kannassa oleva suunnitteluSopimus on tarve poistaa

* poista p-elementti, jossa sama teksti kuin alla olevan elementin sisällä

* korjaa adaptSuunnitteluSopimusToSave toiminnallisuutta
  • Loading branch information
tkork authored Jan 14, 2022
1 parent 7e9811c commit 407ecae
Show file tree
Hide file tree
Showing 17 changed files with 410 additions and 154 deletions.
15 changes: 13 additions & 2 deletions backend/src/handler/projektiAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class ProjektiAdapter {
oid,
muistiinpano,
aloitusKuulutus,
suunnitteluSopimus,
suunnitteluSopimus: adaptSuunnitteluSopimusToSave(projekti, suunnitteluSopimus),
kayttoOikeudet: kayttoOikeudetManager.getKayttoOikeudet(),
lisakuulutuskieli,
eurahoitus,
Expand All @@ -71,7 +71,18 @@ function adaptLiittyvatSuunnitelmat(suunnitelmat?: Suunnitelma[] | null): API.Su
return suunnitelmat as undefined | null;
}

function adaptAloitusKuulutus(kuulutus?: AloitusKuulutus | null): API.AloitusKuulutus | undefined | null {
function adaptSuunnitteluSopimusToSave(
projekti: DBProjekti,
suunnitteluSopimusInput?: API.SuunnitteluSopimusInput | null
): API.SuunnitteluSopimusInput | null | undefined {
if (suunnitteluSopimusInput) {
const { logo, ...rest } = suunnitteluSopimusInput;
return { ...rest, logo: logo || projekti.suunnitteluSopimus?.logo };
}
return suunnitteluSopimusInput as null | undefined;
}

function adaptAloitusKuulutus(kuulutus?: AloitusKuulutus): API.AloitusKuulutus | undefined {
if (kuulutus) {
const { esitettavatYhteystiedot, ...otherKuulutusFields } = kuulutus;
const yhteystiedot: API.Yhteystieto[] | undefined = esitettavatYhteystiedot?.map(
Expand Down
2 changes: 1 addition & 1 deletion backend/src/handler/projektiHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async function createProjektiFromVelho(oid: string, vaylaUser: NykyinenKayttaja,
*/
async function handleFiles(input: TallennaProjektiInput) {
const logo = input.suunnitteluSopimus?.logo;
if (logo && input.suunnitteluSopimus) {
if (logo) {
input.suunnitteluSopimus.logo = await fileService.persistFileToProjekti({
uploadedFileSource: logo,
oid: input.oid,
Expand Down
71 changes: 71 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"pino": "7.6.2",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-dropzone": "^11.5.1",
"react-hook-form": "7.12.2",
"source-map-support": "0.5.19",
"swr": "1.1.0",
Expand Down
38 changes: 23 additions & 15 deletions src/__tests__/__snapshots__/Perusta.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,36 @@ Array [
<label>
Asiatunnus
</label>
<input
className=""
disabled={true}
maxLength={200}
onChange={[Function]}
type="text"
/>
<div
className="flex flex-col"
>
<input
className=""
disabled={true}
maxLength={200}
onChange={[Function]}
type="text"
/>
</div>
</div>
<div
className="form-group"
>
<label>
Projektin nimi
</label>
<input
className=""
maxLength={100}
name="name"
onBlur={[Function]}
onChange={[Function]}
type="text"
/>
<div
className="flex flex-col"
>
<input
className=""
maxLength={100}
name="name"
onBlur={[Function]}
onChange={[Function]}
type="text"
/>
</div>
</div>
<div
className="wrapper"
Expand Down
16 changes: 3 additions & 13 deletions src/components/form/CheckBox.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
import classNames from "classnames";
import React from "react";
import { FieldError } from "react-hook-form";

interface Props {
error?: FieldError;
label?: string;
hideErrorMessage?: boolean;
hideLengthCounter?: boolean;
}

const CheckBox = (
{
maxLength = 200,
error,
label,
hideErrorMessage,
className,
hideLengthCounter = true,
...props
}: Props & Omit<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref">,
ref: React.ForwardedRef<HTMLInputElement>
) => {
return (
<label className="block" htmlFor={props?.id}>
<input type="checkbox" maxLength={maxLength} {...props} ref={ref} className={classNames(error && "error")} />
&nbsp;{label}
<label htmlFor={props?.id}>
<input type="checkbox" {...props} ref={ref} />
<span className="pl-3 pr-6">{label}</span>
</label>
);
};
Expand Down
11 changes: 8 additions & 3 deletions src/components/form/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface Props {
label?: string;
hideErrorMessage?: boolean;
hideLengthCounter?: boolean;
formGroupClassName?: string;
}

const DatePicker = (
Expand All @@ -17,19 +18,23 @@ const DatePicker = (
label,
hideErrorMessage,
className,
hideLengthCounter = true,
formGroupClassName,
...props
}: Props & Omit<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref">,
ref: React.ForwardedRef<HTMLInputElement>
) => {
return (
<FormGroup label={label} errorMessage={hideErrorMessage ? undefined : error?.message} className={className}>
<FormGroup
label={label}
errorMessage={hideErrorMessage ? undefined : error?.message}
className={formGroupClassName}
>
<input
type="date"
maxLength={maxLength}
{...props}
ref={ref}
className={classNames(error && "error", "md:max-w-min")}
className={classNames(className, error && "error")}
/>
</FormGroup>
);
Expand Down
65 changes: 65 additions & 0 deletions src/components/form/FileInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import Button from "@components/button/Button";
import React from "react";
import { FieldError } from "react-hook-form";
import FormGroup from "./FormGroup";
import { DropzoneOptions, useDropzone } from "react-dropzone";
import classNames from "classnames";

type DropzoneProps = {
onChange?: React.ChangeEventHandler<HTMLInputElement>;
label?: string;
error?: FieldError;
bottomInfoText?: string;
hideErrorMessage?: boolean;
} & DropzoneOptions;

export const FileInput = ({
onChange,
label,
error,
bottomInfoText,
hideErrorMessage,
multiple = false,
noClick = true,
maxSize = 4500000,
accept = "image/jpeg, image/png",
...otherDropzoneOptions
}: DropzoneProps) => {
const { getRootProps, getInputProps, isDragActive, open } = useDropzone({
multiple,
noClick,
maxSize,
accept,
...otherDropzoneOptions,
});

return (
<FormGroup label={label} errorMessage={hideErrorMessage ? undefined : error?.message}>
<div
{...getRootProps()}
className={classNames(
"border-dashed border border-gray py-4 flex flex-col justify-center items-center relative",
isDragActive &&
"before:inset-0 before:absolute before:bg-gray-light before:bg-opacity-50 before:z-50 before:pointer-events-none"
)}
>
<p className="mb-4 vayla-paragraph flex flex-wrap justify-center">
<span>Pudota tiedosto tähän tai</span>
</p>
<input {...getInputProps({ onChange })} />
<Button
type="button"
onClick={(e) => {
e.preventDefault();
open();
}}
>
Valitse tiedosto
</Button>
<p className="mt-4 mb-0">{bottomInfoText}</p>
</div>
</FormGroup>
);
};

export default FileInput;
5 changes: 3 additions & 2 deletions src/components/form/FormGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface Props {
maxLength?: number;
length?: number;
bottomInfo?: ReactNode;
flexDirection?: "row" | "col";
}

export default function FormGroup({
Expand All @@ -17,13 +18,13 @@ export default function FormGroup({
errorMessage,
bottomInfo,
className,
flexDirection = "col",
...props
}: Props & React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>): ReactElement {
return (
<div className={classNames(style["form-group"], className)} {...props}>
{label && <label>{label}</label>}
{children}

<div className={classNames("flex", `flex-${flexDirection}`)}>{children}</div>
{(bottomInfo || errorMessage) && (
<div className="flex">
{errorMessage && <span className="text-red">{errorMessage}</span>}
Expand Down
Loading

0 comments on commit 407ecae

Please sign in to comment.