Resource update working
This commit is contained in:
parent
5d1db5413b
commit
94da55450e
5 changed files with 15 additions and 16 deletions
|
@ -11,7 +11,7 @@ import logger from '@server/logger';
|
||||||
|
|
||||||
// Define Zod schema for request parameters validation
|
// Define Zod schema for request parameters validation
|
||||||
const deleteResourceSchema = z.object({
|
const deleteResourceSchema = z.object({
|
||||||
resourceId: z.string().uuid()
|
resourceId: z.string()
|
||||||
});
|
});
|
||||||
|
|
||||||
export async function deleteResource(req: Request, res: Response, next: NextFunction): Promise<any> {
|
export async function deleteResource(req: Request, res: Response, next: NextFunction): Promise<any> {
|
||||||
|
|
|
@ -70,7 +70,7 @@ export async function getResource(req: Request, res: Response, next: NextFunctio
|
||||||
status: HttpCode.OK,
|
status: HttpCode.OK,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
throw error;
|
||||||
return next(createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred..."));
|
return next(createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred..."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import logger from '@server/logger';
|
||||||
|
|
||||||
// Define Zod schema for request parameters validation
|
// Define Zod schema for request parameters validation
|
||||||
const updateResourceParamsSchema = z.object({
|
const updateResourceParamsSchema = z.object({
|
||||||
resourceId: z.string().uuid()
|
resourceId: z.string()
|
||||||
});
|
});
|
||||||
|
|
||||||
// Define Zod schema for request body validation
|
// Define Zod schema for request body validation
|
||||||
|
|
|
@ -27,8 +27,7 @@ import {
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select"
|
} from "@/components/ui/select"
|
||||||
import { Textarea } from "@/components/ui/textarea"
|
import { Textarea } from "@/components/ui/textarea"
|
||||||
import { useSiteContext } from "@app/hooks/useSiteContext"
|
import { useResourceContext } from "@app/hooks/useResourceContext"
|
||||||
import api from "@app/api"
|
|
||||||
|
|
||||||
const GeneralFormSchema = z.object({
|
const GeneralFormSchema = z.object({
|
||||||
name: z.string()
|
name: z.string()
|
||||||
|
@ -50,12 +49,12 @@ const GeneralFormSchema = z.object({
|
||||||
type GeneralFormValues = z.infer<typeof GeneralFormSchema>
|
type GeneralFormValues = z.infer<typeof GeneralFormSchema>
|
||||||
|
|
||||||
export function GeneralForm() {
|
export function GeneralForm() {
|
||||||
const { site, updateSite } = useSiteContext();
|
const { resource, updateResource } = useResourceContext();
|
||||||
|
|
||||||
const form = useForm<GeneralFormValues>({
|
const form = useForm<GeneralFormValues>({
|
||||||
resolver: zodResolver(GeneralFormSchema),
|
resolver: zodResolver(GeneralFormSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
name: site?.name
|
name: resource?.name
|
||||||
},
|
},
|
||||||
mode: "onChange",
|
mode: "onChange",
|
||||||
})
|
})
|
||||||
|
@ -66,7 +65,7 @@ export function GeneralForm() {
|
||||||
// })
|
// })
|
||||||
|
|
||||||
async function onSubmit(data: GeneralFormValues) {
|
async function onSubmit(data: GeneralFormValues) {
|
||||||
await updateSite({ name: data.name });
|
await updateResource({ name: data.name });
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -82,7 +81,7 @@ export function GeneralForm() {
|
||||||
<Input {...field} />
|
<Input {...field} />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>
|
<FormDescription>
|
||||||
This is the display name of the site.
|
This is the display name of the resource.
|
||||||
</FormDescription>
|
</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
@ -147,7 +146,7 @@ export function GeneralForm() {
|
||||||
URLs
|
URLs
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
<FormDescription className={cn(index !== 0 && "sr-only")}>
|
<FormDescription className={cn(index !== 0 && "sr-only")}>
|
||||||
Add links to your website, blog, or social media profiles.
|
Add links to your webresource, blog, or social media profiles.
|
||||||
</FormDescription>
|
</FormDescription>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input {...field} />
|
<Input {...field} />
|
||||||
|
@ -167,7 +166,7 @@ export function GeneralForm() {
|
||||||
Add URL
|
Add URL
|
||||||
</Button>
|
</Button>
|
||||||
</div> */}
|
</div> */}
|
||||||
<Button type="submit">Update Site</Button>
|
<Button type="submit">Update Resource</Button>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
)
|
)
|
||||||
|
|
|
@ -11,11 +11,11 @@ type ResourcesPageProps = {
|
||||||
export default async function Page({ params }: ResourcesPageProps) {
|
export default async function Page({ params }: ResourcesPageProps) {
|
||||||
let resources: ListResourcesResponse["resources"] = [];
|
let resources: ListResourcesResponse["resources"] = [];
|
||||||
try {
|
try {
|
||||||
const res = await internal.get<AxiosResponse<ListResourcesResponse>>(
|
// const res = await internal.get<AxiosResponse<ListResourcesResponse>>(
|
||||||
`/org/${params.orgId}/resources`,
|
// `/org/${params.orgId}/resources`,
|
||||||
authCookieHeader(),
|
// authCookieHeader(),
|
||||||
);
|
// );
|
||||||
resources = res.data.data.resources;
|
// resources = res.data.data.resources;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error fetching resources", e);
|
console.error("Error fetching resources", e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue