Resource update working

This commit is contained in:
Owen Schwartz 2024-10-19 17:41:20 -04:00
parent 5d1db5413b
commit 94da55450e
No known key found for this signature in database
GPG key ID: 8271FDFFD9E0CCBD
5 changed files with 15 additions and 16 deletions

View file

@ -11,7 +11,7 @@ import logger from '@server/logger';
// Define Zod schema for request parameters validation
const deleteResourceSchema = z.object({
resourceId: z.string().uuid()
resourceId: z.string()
});
export async function deleteResource(req: Request, res: Response, next: NextFunction): Promise<any> {

View file

@ -70,7 +70,7 @@ export async function getResource(req: Request, res: Response, next: NextFunctio
status: HttpCode.OK,
});
} catch (error) {
logger.error(error);
throw error;
return next(createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred..."));
}
}

View file

@ -11,7 +11,7 @@ import logger from '@server/logger';
// Define Zod schema for request parameters validation
const updateResourceParamsSchema = z.object({
resourceId: z.string().uuid()
resourceId: z.string()
});
// Define Zod schema for request body validation

View file

@ -27,8 +27,7 @@ import {
SelectValue,
} from "@/components/ui/select"
import { Textarea } from "@/components/ui/textarea"
import { useSiteContext } from "@app/hooks/useSiteContext"
import api from "@app/api"
import { useResourceContext } from "@app/hooks/useResourceContext"
const GeneralFormSchema = z.object({
name: z.string()
@ -50,12 +49,12 @@ const GeneralFormSchema = z.object({
type GeneralFormValues = z.infer<typeof GeneralFormSchema>
export function GeneralForm() {
const { site, updateSite } = useSiteContext();
const { resource, updateResource } = useResourceContext();
const form = useForm<GeneralFormValues>({
resolver: zodResolver(GeneralFormSchema),
defaultValues: {
name: site?.name
name: resource?.name
},
mode: "onChange",
})
@ -66,7 +65,7 @@ export function GeneralForm() {
// })
async function onSubmit(data: GeneralFormValues) {
await updateSite({ name: data.name });
await updateResource({ name: data.name });
}
return (
@ -82,7 +81,7 @@ export function GeneralForm() {
<Input {...field} />
</FormControl>
<FormDescription>
This is the display name of the site.
This is the display name of the resource.
</FormDescription>
<FormMessage />
</FormItem>
@ -147,7 +146,7 @@ export function GeneralForm() {
URLs
</FormLabel>
<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>
<FormControl>
<Input {...field} />
@ -167,7 +166,7 @@ export function GeneralForm() {
Add URL
</Button>
</div> */}
<Button type="submit">Update Site</Button>
<Button type="submit">Update Resource</Button>
</form>
</Form>
)

View file

@ -11,11 +11,11 @@ type ResourcesPageProps = {
export default async function Page({ params }: ResourcesPageProps) {
let resources: ListResourcesResponse["resources"] = [];
try {
const res = await internal.get<AxiosResponse<ListResourcesResponse>>(
`/org/${params.orgId}/resources`,
authCookieHeader(),
);
resources = res.data.data.resources;
// const res = await internal.get<AxiosResponse<ListResourcesResponse>>(
// `/org/${params.orgId}/resources`,
// authCookieHeader(),
// );
// resources = res.data.data.resources;
} catch (e) {
console.error("Error fetching resources", e);
}