Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions studio/web/app/home/organisations/[organisationId]/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,6 @@ export default function Page({ params: { organisationId } }: OrgaisationParam) {
<Image src={UploadImage} alt="logo" width={125} height={125} />
</div>
</div>
</form>
<div className="flex gap-3">
<Link href="/home/organisations">
<Button
variant="outline"
className="rounded-md text-[#376789] border-[#376789]"
>
Cancel
</Button>
</Link>
<Button
onClick={handleSubmit(async (data) => {
try {
Expand All @@ -161,10 +151,20 @@ export default function Page({ params: { organisationId } }: OrgaisationParam) {
toast.error("Something went wrong");
}
})}
className="rounded-md bg-[#376789] text-white"
className="rounded-md bg-[#376789] text-white w-full"
>
Edit Organisation
</Button>
</form>
<div className="flex gap-3">
<Link href="/home/organisations">
<Button
variant="outline"
className="rounded-md text-[#376789] border-[#376789]"
>
Cancel
</Button>
</Link>
</div>
</div>
</main>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"use client";
import React, { useState } from "react";
import React, { useRef, useState } from "react";
import { Button } from "@/components/ui/Button";
import { Input } from "@/components/dataEntry/input";
import { Label } from "@/components/dataEntry/label";
import Link from "next/link";
import Image from "next/image";
import { ProjectParam } from "@/types/params/project_param";
import { CreateFileSchema, createFileSchema } from "@/lib/zod/validators/files";
import axios, { AxiosError } from "axios";
Expand All @@ -14,19 +15,30 @@ import { useRouter } from "next/navigation";
import UppyUploader from "@/components/UppyUploader";
import { getServerUrl } from "@/lib/utils/serverUrl";
import { kavachAxiosConfig } from "@/lib/utils/kavachAxiosConfig";
import UploadImage from "@/assets/uploadImage.png";
import FileImage from "@/assets/document.png";
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
import { title } from "process";

export default function Page({
params: { projectId, organisationId },
}: ProjectParam) {
const {
handleSubmit,
register,
formState: { errors },
formState,
getValues
} = useForm<CreateFileSchema>({
resolver: zodResolver(createFileSchema),
});
const [title, setTitle] = useState<string>("");
const [filename, setFilename] = useState<string>("");
const [uploadDialogOpen, setUploadDialogOpen] = useState<boolean>(false)
const router = useRouter();
const {errors} = formState

const diableAddButton = filename === '' || title === ''

return (
<main className="flex flex-col mt-10 bg-transparent">
<div className="flex flex-row justify-around items-start">
Expand All @@ -41,6 +53,7 @@ export default function Page({
id="title"
{...register("name")}
placeholder="Enter the title"
onChange={(e) => setTitle(e.target.value)}
/>
{errors.name ? (
<div className="text-red-500 italic text-xs">
Expand All @@ -50,28 +63,35 @@ export default function Page({
""
)}
</div>
<div>
<UppyUploader
onUpload={(_, path) => {
setFilename(path);
}}
isDataset={true}
/>
<div className="grid w-full items-center gap-3">
<Label htmlFor="title" className="font-normal">
Upload Dataset
</Label>
<Dialog open={uploadDialogOpen} onOpenChange={setUploadDialogOpen}>
<DialogTrigger asChild>
<div className="p-6 border border-input rounded-md w-fit cursor-pointer">
<Image
src={filename !== '' ? FileImage : UploadImage}
alt="logo"
width={125}
height={125}
/>
{filename}
</div>
</DialogTrigger>
<DialogContent className="w-fit max-w-4xl">
<UppyUploader
onUpload={(_, path) => {
setFilename(path);
setUploadDialogOpen(false);
}}
isDataset={true}
/>
</DialogContent>
</Dialog>
</div>
</form>
<div className="flex gap-3">
<Button
variant="outline"
className="rounded-md text-[#376789] border-[#376789]"
asChild
>
<Link
href={`/home/organisations/${organisationId}/projects/${projectId}/`}
>
Cancel
</Link>
</Button>
<Button
disabled={diableAddButton || false}
onClick={handleSubmit(async (data) => {
const file = {
name: data.name.trim(),
Expand Down Expand Up @@ -101,10 +121,23 @@ export default function Page({
toast.error("Something went wrong");
}
})}
className="rounded-md bg-[#376789] text-white"
className="rounded-md bg-[#376789] text-white w-full"
>
Add Dataset
</Button>
</form>
<div className="flex gap-3">
<Button
variant="outline"
className="rounded-md text-[#376789] border-[#376789]"
asChild
>
<Link
href={`/home/organisations/${organisationId}/projects/${projectId}/`}
>
Cancel
</Link>
</Button>
</div>
</div>
</main>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import { Button } from "@/components/ui/Button";
import { Input } from "@/components/dataEntry/input";
import { Label } from "@/components/dataEntry/label";
import { Textarea } from "@/components/dataEntry/textarea";
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import Link from "next/link";
import { useForm } from "react-hook-form";
import { useOrganisationsStore } from "@/lib/zustand/organisation";
Expand Down Expand Up @@ -39,6 +31,7 @@ export default function Page({
register,
formState: { errors },
setValue,
watch,
} = useForm<CreateProjectSchema>({
resolver: zodResolver(createProjectSchema),
});
Expand Down Expand Up @@ -94,46 +87,15 @@ export default function Page({
);
}

const currentOrganisation = organisations.find(
(org) => parseInt(org.id) === parseInt(orgId),
);
const titleValue = watch("title");

const disableButton = titleValue === undefined || titleValue === "";``

return (
<main className="flex flex-col mt-10 bg-transparent">
<div className="flex flex-row justify-around items-start">
<h1 className="text-xl font-semibold">Edit {project.title}</h1>
<form className="flex flex-col items-center w-2/5 mt-20 gap-10">
<div className="grid w-full items-center gap-3">
<Label htmlFor="organisation" className="font-normal">
Organisation
</Label>
<Select
onValueChange={(value) => {
organisations.map((org) => {
if (org.title === value) {
newOrgId = org.id;
}
});
}}
>
<SelectTrigger className="w-full">
<SelectValue
placeholder={currentOrganisation?.title}
></SelectValue>
</SelectTrigger>
<SelectContent>
<SelectGroup>
{organisations.map((org) => {
return (
<SelectItem key={org.id} value={org.title}>
{org.title}
</SelectItem>
);
})}
</SelectGroup>
</SelectContent>
</Select>
</div>
<div className="grid w-full items-center gap-3">
<Label htmlFor="title" className="font-normal">
Title
Expand Down Expand Up @@ -165,16 +127,8 @@ export default function Page({
</p>
)}
</div>
</form>
<div className="flex gap-3">
<Button
variant="outline"
className="rounded-md text-[#376789] border-[#376789]"
asChild
>
<Link href={`/home/organisations/${orgId}`}>Cancel</Link>
</Button>
<Button
disabled={disableButton}
onClick={handleSubmit(async (data) => {
if (newOrgId !== orgId) {
try {
Expand Down Expand Up @@ -218,10 +172,19 @@ export default function Page({
toast.error("Something went wrong");
}
})}
className="rounded-md bg-[#376789] text-white"
className="rounded-md bg-[#376789] text-white w-full"
>
Edit Project
</Button>
</form>
<div className="flex gap-3">
<Button
variant="outline"
className="rounded-md text-[#376789] border-[#376789]"
asChild
>
<Link href={`/home/organisations/${orgId}`}>Cancel</Link>
</Button>
</div>
</div>
</main>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import { Button } from "@/components/ui/Button";
import { Input } from "@/components/dataEntry/input";
import { Label } from "@/components/dataEntry/label";
import { Textarea } from "@/components/dataEntry/textarea";
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import Link from "next/link";
import { useForm } from "react-hook-form";
import { useOrganisationsStore } from "@/lib/zustand/organisation";
Expand All @@ -38,6 +30,7 @@ export default function Page({
handleSubmit,
register,
formState: { errors },
watch
} = useForm<CreateProjectSchema>({
resolver: zodResolver(createProjectSchema),
});
Expand All @@ -60,40 +53,14 @@ export default function Page({
getOrganisations();
}, []);

const watchTitle = watch("title");
const disableButton = watchTitle === undefined || watchTitle === "" || orgId === undefined || orgId === "";

return (
<main className="flex flex-col mt-10 bg-transparent">
<div className="flex flex-row justify-around items-start">
<h1 className="text-xl font-semibold">Create New Project </h1>
<form className="flex flex-col items-center w-2/5 mt-20 gap-10">
<div className="grid w-full items-center gap-3">
<Label htmlFor="organisation" className="font-normal">
Organisation
</Label>
<Select
onValueChange={(value) => {
organisations.map((org) => {
if (org.title === value) {
orgId = org.id;
}
});
}}
>
<SelectTrigger className="w-full">
<SelectValue placeholder={"Select Organisation"}></SelectValue>
</SelectTrigger>
<SelectContent>
<SelectGroup>
{organisations.map((org) => {
return (
<SelectItem key={org.id} value={org.title}>
{org.title}
</SelectItem>
);
})}
</SelectGroup>
</SelectContent>
</Select>
</div>
<div className="grid w-full items-center gap-3">
<Label htmlFor="title" className="font-normal">
Title
Expand Down Expand Up @@ -125,16 +92,8 @@ export default function Page({
</p>
)}
</div>
</form>
<div className="flex gap-3">
<Button
variant="outline"
className="rounded-md text-[#376789] border-[#376789]"
asChild
>
<Link href={`/home/organisations/${orgId}`}>Cancel</Link>
</Button>
<Button
disabled={disableButton}
onClick={handleSubmit(async (data) => {
try {
await axios.post(
Expand All @@ -156,10 +115,19 @@ export default function Page({
toast.error("Something went wrong");
}
})}
className="rounded-md bg-[#376789] text-white"
className="rounded-md bg-[#376789] text-white w-full"
>
Create Project
</Button>
</form>
<div className="flex gap-3">
<Button
variant="outline"
className="rounded-md text-[#376789] border-[#376789]"
asChild
>
<Link href={`/home/organisations/${orgId}`}>Cancel</Link>
</Button>
</div>
</div>
</main>
Expand Down
Loading