From 5e8b7d9bbf5a3a88d70aede3648f0fc7fe0aebdf Mon Sep 17 00:00:00 2001 From: shika Date: Wed, 27 Nov 2024 09:10:30 +0700 Subject: [PATCH 01/10] feat: add rekomendasi form --- src/api/generated/ApiClient.ts | 4 + src/api/generated/index.ts | 3 + src/api/generated/models/CoWorking.ts | 14 + .../generated/models/LocationCategories.ts | 5 + src/api/generated/models/Voucher.ts | 13 + .../services/RecommendationService.ts | 318 ++++++++++++++++++ src/assets/icons/rekomendasi/docs.svg | 4 + src/assets/icons/rekomendasi/marker.svg | 4 + .../custom-form/fields/FormTextField.tsx | 2 +- src/routeTree.gen.ts | 20 ++ .../-components/AddCoWorkingSpaceDialog.tsx | 106 ++++++ .../-components/AddCoWorkingSpaceDrawer.tsx | 90 +++++ .../-components/AddVoucherDialog.tsx | 96 ++++++ .../-components/AddVoucherDrawer.tsx | 83 +++++ .../home/rekomendasi/-constants.ts | 38 +++ .../home/rekomendasi/-useAddCoWorkingSpace.ts | 104 ++++++ .../home/rekomendasi/-useAddVoucher.ts | 100 ++++++ .../rekomendasi/-useLocationCategories.ts | 19 ++ 18 files changed, 1022 insertions(+), 1 deletion(-) create mode 100644 src/api/generated/models/CoWorking.ts create mode 100644 src/api/generated/models/LocationCategories.ts create mode 100644 src/api/generated/models/Voucher.ts create mode 100644 src/api/generated/services/RecommendationService.ts create mode 100644 src/assets/icons/rekomendasi/docs.svg create mode 100644 src/assets/icons/rekomendasi/marker.svg create mode 100644 src/routes/_app/_left-navbar/home/rekomendasi/-components/AddCoWorkingSpaceDialog.tsx create mode 100644 src/routes/_app/_left-navbar/home/rekomendasi/-components/AddCoWorkingSpaceDrawer.tsx create mode 100644 src/routes/_app/_left-navbar/home/rekomendasi/-components/AddVoucherDialog.tsx create mode 100644 src/routes/_app/_left-navbar/home/rekomendasi/-components/AddVoucherDrawer.tsx create mode 100644 src/routes/_app/_left-navbar/home/rekomendasi/-constants.ts create mode 100644 src/routes/_app/_left-navbar/home/rekomendasi/-useAddCoWorkingSpace.ts create mode 100644 src/routes/_app/_left-navbar/home/rekomendasi/-useAddVoucher.ts create mode 100644 src/routes/_app/_left-navbar/home/rekomendasi/-useLocationCategories.ts diff --git a/src/api/generated/ApiClient.ts b/src/api/generated/ApiClient.ts index 2fe57fd..08a0970 100644 --- a/src/api/generated/ApiClient.ts +++ b/src/api/generated/ApiClient.ts @@ -10,6 +10,7 @@ import { CalendarService } from './services/CalendarService'; import { CategoryService } from './services/CategoryService'; import { CommentService } from './services/CommentService'; import { CompetitionsService } from './services/CompetitionsService'; +import { RecommendationService } from './services/RecommendationService'; import { CourseService } from './services/CourseService'; import { CurhatService } from './services/CurhatService'; import { InfoService } from './services/InfoService'; @@ -22,6 +23,7 @@ import { TestimoniService } from './services/TestimoniService'; import { UnsubscribeService } from './services/UnsubscribeService'; import { UserFinderService } from './services/UserFinderService'; import { UserProfileService } from './services/UserProfileService'; + type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest; export class ApiClient { public readonly auth: AuthService; @@ -29,6 +31,7 @@ export class ApiClient { public readonly category: CategoryService; public readonly comment: CommentService; public readonly competitions: CompetitionsService; + public readonly recommendation: RecommendationService; public readonly course: CourseService; public readonly curhat: CurhatService; public readonly info: InfoService; @@ -57,6 +60,7 @@ export class ApiClient { this.auth = new AuthService(this.request); this.calendar = new CalendarService(this.request); this.category = new CategoryService(this.request); + this.recommendation = new RecommendationService(this.request); this.comment = new CommentService(this.request); this.competitions = new CompetitionsService(this.request); this.course = new CourseService(this.request); diff --git a/src/api/generated/index.ts b/src/api/generated/index.ts index d43db09..322bca2 100644 --- a/src/api/generated/index.ts +++ b/src/api/generated/index.ts @@ -22,6 +22,9 @@ export type { Comment } from './models/Comment'; export type { CommentWithReactions } from './models/CommentWithReactions'; export type { Competition } from './models/Competition'; export type { CompetitionCategories } from './models/CompetitionCategories'; +export type { Voucher } from './models/Voucher'; +export type { CoWorking } from './models/CoWorking'; +export type { LocationCategories } from './models/LocationCategories'; export type { Course } from './models/Course'; export type { Error } from './models/Error'; export type { Info } from './models/Info'; diff --git a/src/api/generated/models/CoWorking.ts b/src/api/generated/models/CoWorking.ts new file mode 100644 index 0000000..9a53e7e --- /dev/null +++ b/src/api/generated/models/CoWorking.ts @@ -0,0 +1,14 @@ +/* generated using openapi-typescript-codegen -- do not edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { LocationCategories } from './LocationCategories'; +export type CoWorking = { + title: string; + imageUrl: string; + location: LocationCategories; + address: string; + mapUrl: string; + description: string | null; +}; + diff --git a/src/api/generated/models/LocationCategories.ts b/src/api/generated/models/LocationCategories.ts new file mode 100644 index 0000000..8bad5d9 --- /dev/null +++ b/src/api/generated/models/LocationCategories.ts @@ -0,0 +1,5 @@ +/* generated using openapi-typescript-codegen -- do not edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type LocationCategories = Array<'Ganesha' | 'Jatinangor'>; diff --git a/src/api/generated/models/Voucher.ts b/src/api/generated/models/Voucher.ts new file mode 100644 index 0000000..13c8e93 --- /dev/null +++ b/src/api/generated/models/Voucher.ts @@ -0,0 +1,13 @@ +/* generated using openapi-typescript-codegen -- do not edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type Voucher = { + title: string; + imageUrl: string; + link: string| null; + periodeAwal: string| null; + periodeAkhir: string| null; + description: string | null; +}; + diff --git a/src/api/generated/services/RecommendationService.ts b/src/api/generated/services/RecommendationService.ts new file mode 100644 index 0000000..c5d7921 --- /dev/null +++ b/src/api/generated/services/RecommendationService.ts @@ -0,0 +1,318 @@ +/* generated using openapi-typescript-codegen -- do not edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { Voucher } from '../models/Voucher'; +import type { CoWorking } from '../models/CoWorking'; +import type { LocationCategories } from '../models/LocationCategories'; +import type { CancelablePromise } from '../core/CancelablePromise'; +import type { BaseHttpRequest } from '../core/BaseHttpRequest'; +export class RecommendationService { + constructor(public readonly httpRequest: BaseHttpRequest) {} + /** + * @returns any Created coworking + * @throws ApiError + */ + public createCoWorkingSpace({ + requestBody, + }: { + requestBody?: { + title: string; + imageURL: Array; + location: LocationCategories; + address: string; + mapsURL: string; + description?: string | null; + }, + }): CancelablePromise<{ + coWorkingSpaceId: string; + title: string; + location: Array<'Ganesha' | 'Jatinangor'>; + address: string; + mapsURL: string; + description: string | null; + imageURL: Array<{ + coWorkinSpaceId: string; + mediaId: string; + order: number; + media: { + id: string; + creatorId: string; + name: string; + type: string; + url: string; + createdAt: string; + }; + }>; + }> { + return this.httpRequest.request({ + method: 'POST', + url: '/api/rekomendasi/co-working-space', + body: requestBody, + mediaType: 'application/json', + errors: { + 400: `Bad request`, + }, + }); + } + /** + * @returns any Fetched list of coworkingspace + * @throws ApiError + */ + public getCoWorkingSpaceList({ + filter, + offset, + }: { + /** + * is active or not + */ + filter?: string, + + offset?: number | null, + }): CancelablePromise<{ + vouchers: Array; + }> { + return this.httpRequest.request({ + method: 'GET', + url: '/api/rekomendasi/co-working-space', + query: { + 'filter': filter, + 'offset': offset, + }, + errors: { + 400: `Bad request: validation error`, + }, + }); + } + /** + * @returns any Updated coworkingspace + * @throws ApiError + */ + public updateCoWorkingSpace({ + id, + requestBody, + }: { + id: string, + requestBody?: { + title?: string; + imageURL?: Array; + location?: LocationCategories; + address?: string; + mapsURL?: string; + description?: string | null; + }, + }): CancelablePromise<{ + coWorkingSpaceId: string; + title: string; + location: Array<'Ganesha' | 'Jatinangor'>; + address: string; + mapsURL: string; + description: string | null; + imageURL?: Array<{ + coWorkingSpaceId: string; + mediaId: string; + order: number; + media: { + id: string; + creatorId: string; + name: string; + type: string; + url: string; + createdAt: string; + }; + }>; + }> { + return this.httpRequest.request({ + method: 'PUT', + url: '/api/rekomendasi/co-working-space/{id}', + path: { + 'id': id, + }, + body: requestBody, + mediaType: 'application/json', + errors: { + 400: `Bad request`, + 404: `Competition not found`, + }, + }); + } + /** + * @returns coworkingspace Successfully deleted comment + * @throws ApiError + */ + public deleteCoWorkingSpace({ + coWorkingSpaceId, + }: { + /** + * Id of fetched/deleted coworkingspace + */ + coWorkingSpaceId: string, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'DELETE', + url: '/api/rekomendasi/co-working-space/{coWorkingSpaceId}', + path: { + 'coWorkingSpaceId': coWorkingSpaceId, + }, + errors: { + 400: `Bad request`, + 404: `Error`, + 500: `Internal server error`, + }, + }); + } + + /** + * @returns any Created voucher + * @throws ApiError + */ + public createVoucher({ + requestBody, + }: { + requestBody?: { + title: string; + imageURL: Array; + link: string; + periodeAwal?: string | null; + periodeAkhir?: string | null; + description?: string | null; + }, + }): CancelablePromise<{ + voucherId: string; + title: string; + link: string; + periodeAwal: string | null; + periodeAkhir: string | null; + description: string | null + imageURL: Array<{ + voucherId: string; + mediaId: string; + order: number; + media: { + id: string; + creatorId: string; + name: string; + type: string; + url: string; + createdAt: string; + }; + }>; + }> { + return this.httpRequest.request({ + method: 'POST', + url: '/api/rekomendasi/voucher', + body: requestBody, + mediaType: 'application/json', + errors: { + 400: `Bad request`, + }, + }); + } + /** + * @returns any Fetched list of vouchers + * @throws ApiError + */ + public getVoucherList({ + filter, + offset, + }: { + /** + * is active or not + */ + filter?: string, + + offset?: number | null, + }): CancelablePromise<{ + vouchers: Array; + }> { + return this.httpRequest.request({ + method: 'GET', + url: '/api/rekomendasi/voucher', + query: { + 'filter': filter, + 'offset': offset, + }, + errors: { + 400: `Bad request: validation error`, + }, + }); + } + /** + * @returns any Updated voucher + * @throws ApiError + */ + public updateVoucher({ + id, + requestBody, + }: { + id: string, + requestBody?: { + title?: string; + imageURL?: Array; + link?: string; + periodeAwal?: string | null; + periodeAkhir?: string | null; + description?: string | null; + }, + }): CancelablePromise<{ + voucherId: string; + title: string; + link: string; + periodeAwal: string | null; + periodeAkhir: string | null; + description: string | null; + imageURL?: Array<{ + voucherId: string; + mediaId: string; + order: number; + media: { + id: string; + creatorId: string; + name: string; + type: string; + url: string; + createdAt: string; + }; + }>; + }> { + return this.httpRequest.request({ + method: 'PUT', + url: '/api/rekomendasi/voucher/{id}', + path: { + 'id': id, + }, + body: requestBody, + mediaType: 'application/json', + errors: { + 400: `Bad request`, + 404: `Competition not found`, + }, + }); + } + /** + * @returns voucher Successfully deleted comment + * @throws ApiError + */ + public deleteVoucher({ + voucherId, + }: { + /** + * Id of fetched/deleted vouchers + */ + voucherId: string, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'DELETE', + url: '/api/rekomendasi/voucher/{voucherId}', + path: { + 'voucherId': voucherId, + }, + errors: { + 400: `Bad request`, + 404: `Error`, + 500: `Internal server error`, + }, + }); + } + +} diff --git a/src/assets/icons/rekomendasi/docs.svg b/src/assets/icons/rekomendasi/docs.svg new file mode 100644 index 0000000..1813f9b --- /dev/null +++ b/src/assets/icons/rekomendasi/docs.svg @@ -0,0 +1,4 @@ + + + diff --git a/src/assets/icons/rekomendasi/marker.svg b/src/assets/icons/rekomendasi/marker.svg new file mode 100644 index 0000000..7ed986c --- /dev/null +++ b/src/assets/icons/rekomendasi/marker.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/components/custom-form/fields/FormTextField.tsx b/src/components/custom-form/fields/FormTextField.tsx index af6d034..fee1909 100644 --- a/src/components/custom-form/fields/FormTextField.tsx +++ b/src/components/custom-form/fields/FormTextField.tsx @@ -42,7 +42,7 @@ export default function FormTextField( diff --git a/src/routeTree.gen.ts b/src/routeTree.gen.ts index 6a9393a..324e0d1 100644 --- a/src/routeTree.gen.ts +++ b/src/routeTree.gen.ts @@ -28,6 +28,7 @@ import { Route as AppLeftNavbarSettingsSettingsItemImport } from './routes/_app/ import { Route as AppLeftNavbarHomeTestimoniImport } from './routes/_app/_left-navbar/home/testimoni' import { Route as AppLeftNavbarTimelineInfoIdIndexImport } from './routes/_app/_left-navbar/timeline/$infoId/index' import { Route as AppLeftNavbarHomeTestimoniIndexImport } from './routes/_app/_left-navbar/home/testimoni/index' +import { Route as AppLeftNavbarHomeRekomendasiIndexImport } from './routes/_app/_left-navbar/home/rekomendasi/index' import { Route as AppLeftNavbarHomeNimFinderIndexImport } from './routes/_app/_left-navbar/home/nim-finder/index' import { Route as AppLeftNavbarHomeDingdongIndexImport } from './routes/_app/_left-navbar/home/dingdong/index' import { Route as AppLeftNavbarHomeCurhatIndexImport } from './routes/_app/_left-navbar/home/curhat/index' @@ -136,6 +137,12 @@ const AppLeftNavbarHomeTestimoniIndexRoute = getParentRoute: () => AppLeftNavbarHomeTestimoniRoute, } as any) +const AppLeftNavbarHomeRekomendasiIndexRoute = + AppLeftNavbarHomeRekomendasiIndexImport.update({ + path: '/home/rekomendasi/', + getParentRoute: () => AppLeftNavbarRoute, + } as any) + const AppLeftNavbarHomeNimFinderIndexRoute = AppLeftNavbarHomeNimFinderIndexImport.update({ path: '/home/nim-finder/', @@ -332,6 +339,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof AppLeftNavbarHomeNimFinderIndexImport parentRoute: typeof AppLeftNavbarImport } + '/_app/_left-navbar/home/rekomendasi/': { + id: '/_app/_left-navbar/home/rekomendasi/' + path: '/home/rekomendasi' + fullPath: '/home/rekomendasi' + preLoaderRoute: typeof AppLeftNavbarHomeRekomendasiIndexImport + parentRoute: typeof AppLeftNavbarImport + } '/_app/_left-navbar/home/testimoni/': { id: '/_app/_left-navbar/home/testimoni/' path: '/' @@ -427,6 +441,7 @@ export const routeTree = rootRoute.addChildren({ AppLeftNavbarHomeCurhatIndexRoute, AppLeftNavbarHomeDingdongIndexRoute, AppLeftNavbarHomeNimFinderIndexRoute, + AppLeftNavbarHomeRekomendasiIndexRoute, AppLeftNavbarTimelineInfoIdIndexRoute, AppLeftNavbarHomeTestimoniTypeSemesterCourseIdIndexRoute, }), @@ -473,6 +488,7 @@ export const routeTree = rootRoute.addChildren({ "/_app/_left-navbar/home/curhat/", "/_app/_left-navbar/home/dingdong/", "/_app/_left-navbar/home/nim-finder/", + "/_app/_left-navbar/home/rekomendasi/", "/_app/_left-navbar/timeline/$infoId/", "/_app/_left-navbar/home/testimoni/$type/$semester/$courseId/" ] @@ -553,6 +569,10 @@ export const routeTree = rootRoute.addChildren({ "filePath": "_app/_left-navbar/home/nim-finder/index.tsx", "parent": "/_app/_left-navbar" }, + "/_app/_left-navbar/home/rekomendasi/": { + "filePath": "_app/_left-navbar/home/rekomendasi/index.tsx", + "parent": "/_app/_left-navbar" + }, "/_app/_left-navbar/home/testimoni/": { "filePath": "_app/_left-navbar/home/testimoni/index.tsx", "parent": "/_app/_left-navbar/home/testimoni" diff --git a/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddCoWorkingSpaceDialog.tsx b/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddCoWorkingSpaceDialog.tsx new file mode 100644 index 0000000..cb002b8 --- /dev/null +++ b/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddCoWorkingSpaceDialog.tsx @@ -0,0 +1,106 @@ +import { useEffect } from 'react'; +import CategoryIcon from '~/assets/icons/competition/category.svg'; +import ClockIcon from '~/assets/icons/clock.svg'; +import DocsIcon from '~/assets/icons/rekomendasi/docs.svg'; +import LinkIcon from '~/assets/icons/competition/link.svg'; +import MarkerIcon from '~/assets/icons/rekomendasi/marker.svg'; +import Attachment from '~/components/custom-form/fields/Attachment'; +import DesktopForm from '~/components/custom-form/DesktopForm'; +import DesktopTitleField from '~/components/custom-form/fields/DesktopTitleField'; +import FormTextField from '~/components/custom-form/fields/FormTextField'; +import SingleSelect from '~/components/custom-form/fields/SingleSelect'; +import useAddCoWorkingSpace from '../-useAddCoWorkingSpace'; + +type ComponentProps = { + isOpen: boolean; + setOpen: React.Dispatch>; + constraintRef: React.MutableRefObject; +}; + +export default function AddCoWorkingSpaceDialog(props: Readonly) { + const { isOpen, setOpen, constraintRef } = props; + + + const { categoryOptions, form, onSubmit, image, setImage } = + useAddCoWorkingSpace({ + onSubmitSuccess: () => setOpen(false), + }); + + + useEffect(() => { + if (!isOpen) { + form.reset(); + setImage(null); + } + }, [isOpen]); + + if (!isOpen) { + return null; + } + + return ( + + + + + + + + + + + + + + + + ); +} diff --git a/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddCoWorkingSpaceDrawer.tsx b/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddCoWorkingSpaceDrawer.tsx new file mode 100644 index 0000000..f82ce1b --- /dev/null +++ b/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddCoWorkingSpaceDrawer.tsx @@ -0,0 +1,90 @@ +import { useEffect } from 'react'; +import DocsIcon from '~/assets/icons/rekomendasi/docs.svg' +import BookIcon from '~/assets/icons/calendar/book.svg'; +import LinkIcon from '~/assets/icons/competition/link.svg'; +import MarkerIcon from '~/assets/icons/rekomendasi/marker.svg'; +import Attachment from '~/components/custom-form/fields/Attachment'; +import FormTextField from '~/components/custom-form/fields/FormTextField'; +import MobileForm from '~/components/custom-form/MobileForm'; +import SingleSelect from '~/components/custom-form/fields/SingleSelect'; +import useAddCoWorkingSpace from '../-useAddCoWorkingSpace'; + +type ComponentProps = { + isOpen: boolean; + setOpen: React.Dispatch>; +}; + +export function AddCoWorkingSpaceDrawer(props: Readonly) { + const { isOpen, setOpen } = props; + + const { categoryOptions, form, onSubmit, image, setImage } = + useAddCoWorkingSpace({ + onSubmitSuccess: () => setOpen(false), + }); + + useEffect(() => { + if (!isOpen) { + form.reset(); + setImage(null); + } + }, [isOpen]); + + return ( + + + + + + + + + + + + + + + + ); +} diff --git a/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddVoucherDialog.tsx b/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddVoucherDialog.tsx new file mode 100644 index 0000000..97bb986 --- /dev/null +++ b/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddVoucherDialog.tsx @@ -0,0 +1,96 @@ +import { useEffect } from 'react'; +import ClockIcon from '~/assets/icons/clock.svg'; +import BookIcon from '~/assets/icons/calendar/book.svg'; +import LinkIcon from '~/assets/icons/competition/link.svg'; +import Attachment from '~/components/custom-form/fields/Attachment'; +import DatePicker from '~/components/custom-form/fields/DatePicker'; +import DesktopForm from '~/components/custom-form/DesktopForm'; +import DesktopTitleField from '~/components/custom-form/fields/DesktopTitleField'; +import FormTextField from '~/components/custom-form/fields/FormTextField'; +import useAddVoucher from '../-useAddVoucher'; + +type ComponentProps = { + isOpen: boolean; + setOpen: React.Dispatch>; + constraintRef: React.MutableRefObject; +}; + +export default function AddVoucherDialog(props: Readonly) { + const { isOpen, setOpen, constraintRef } = props; + + const { form, onSubmit, image, setImage } = + useAddVoucher({ + onSubmitSuccess: () => setOpen(false), + }); + + useEffect(() => { + if (!isOpen) { + form.reset(); + setImage(null); + } + }, [isOpen]); + + if (!isOpen) { + return null; + } + + return ( + + + + + + + + + + + + + ); +} diff --git a/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddVoucherDrawer.tsx b/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddVoucherDrawer.tsx new file mode 100644 index 0000000..acb86b8 --- /dev/null +++ b/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddVoucherDrawer.tsx @@ -0,0 +1,83 @@ +import { useEffect } from 'react'; +import ClockIcon from '~/assets/icons/competition/clock.svg'; +import LinkIcon from '~/assets/icons/competition/link.svg'; +import BookIcon from '~/assets/icons/calendar/book.svg'; +import Attachment from '~/components/custom-form/fields/Attachment'; +import DatePicker from '~/components/custom-form/fields/DatePicker'; +import FormTextField from '~/components/custom-form/fields/FormTextField'; +import MobileForm from '~/components/custom-form/MobileForm'; +import useAddVoucher from '../-useAddVoucher'; + +type ComponentProps = { + isOpen: boolean; + setOpen: React.Dispatch>; +}; + +export function AddVoucherDrawer(props: Readonly) { + const { isOpen, setOpen } = props; + + const {form, onSubmit, image, setImage } = + useAddVoucher({ + onSubmitSuccess: () => setOpen(false), + }); + + useEffect(() => { + if (!isOpen) { + form.reset(); + setImage(null); + } + }, [isOpen]); + + return ( + + + + + + + + + + + + + ); +} diff --git a/src/routes/_app/_left-navbar/home/rekomendasi/-constants.ts b/src/routes/_app/_left-navbar/home/rekomendasi/-constants.ts new file mode 100644 index 0000000..0075388 --- /dev/null +++ b/src/routes/_app/_left-navbar/home/rekomendasi/-constants.ts @@ -0,0 +1,38 @@ +import { z } from 'zod'; +import { isGreater } from '~/lib/date'; + +export const VoucherSchema = z + .object({ + title: z.string().min(1), + imageURL: z.string(), + link: z.string().min(1), + periodeAwal: z.string().datetime(), + periodeAkhir: z.string().datetime(), + description: z.string().datetime(), + }) + .refine( + (data) => isGreater(data.periodeAkhir, data.periodeAwal), + { + message: 'Voucher end date must be greater than the start date.', + path: ['voucherDeadline'], + }, + ); + +export type VoucherSchemaType = z.infer; + +export const CoWorkingSpaceSchema = z + .object({ + title: z.string().min(1), + imageURL: z.string(), + location: z + .object({ + id: z.string().min(1), + title: z.string().min(1), + }) + .array(), + address: z.string().min(1), + mapsURL: z.string(), + description: z.string().datetime(), + }); + +export type CoWorkingSpaceSchemaType = z.infer; \ No newline at end of file diff --git a/src/routes/_app/_left-navbar/home/rekomendasi/-useAddCoWorkingSpace.ts b/src/routes/_app/_left-navbar/home/rekomendasi/-useAddCoWorkingSpace.ts new file mode 100644 index 0000000..646d3fa --- /dev/null +++ b/src/routes/_app/_left-navbar/home/rekomendasi/-useAddCoWorkingSpace.ts @@ -0,0 +1,104 @@ +import { useState } from 'react'; +import { useLocationCategories } from './-useLocationCategories'; +import { useForm } from 'react-hook-form'; +import { CoWorkingSpaceSchema, CoWorkingSpaceSchemaType} from './-constants'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { useMutation } from '@tanstack/react-query'; +import { api, queryClient } from '~/api/client'; +import toast from 'react-hot-toast'; +import { LocationCategories, PresignedURL } from '~/api/generated'; +import { FileUpload } from '../../add-announcement'; + +const TOAST_ID = 'add-coworkingspace-toast'; + +type ComponentProps = { + onSubmitSuccess?: () => void; +}; + +export default function useAddCoWorkingSpace(props: Readonly) { + const { onSubmitSuccess } = props; + + const [image, setImage] = useState(null); + const [pendingUpload, setPendingUpload] = useState(null); + const categoryOptions = useLocationCategories(); + + const form = useForm({ + resolver: zodResolver(CoWorkingSpaceSchema), + defaultValues: { + title: '', + imageURL: '', + location: [], + address: '', + mapsURL: '', + description: '', + }, + }); + + const postCoWorkingSpace = useMutation({ + mutationFn: api.recommendation.createCoWorkingSpace.bind(api.recommendation), + onSuccess: () => { + toast.success('CoWorkingSpace Posted!', { id: TOAST_ID }); + queryClient.invalidateQueries({ queryKey: ['coworkingspace'] }); + setPendingUpload(''); + onSubmitSuccess?.(); + }, + onError: () => toast.error('Failed to post CoWorkingSpace', { id: TOAST_ID }), + }); + + const postMediaUpload = useMutation({ + mutationFn: api.media.createPresignedUrl.bind(api.media), + }); + + const onSubmit = async (values: CoWorkingSpaceSchemaType) => { + toast.loading('Please wait...', { id: TOAST_ID }); + + try { + if (!pendingUpload && image) { + const presignedUrl: PresignedURL = await postMediaUpload.mutateAsync({ + requestBody: { + fileName: image.file.name.split('.')[0], + fileType: image.file.name.split('.').at(-1) ?? '', + }, + }); + await fetch(presignedUrl.presignedUrl, { + method: 'PUT', + body: image.file, + }).then(() => + setPendingUpload(() => { + postCoWorkingSpace.mutate({ + requestBody: { + title: values.title, + address: values.address, + mapsURL: values.mapsURL, + location: values.location.map( + (c) => c.title, + ) as LocationCategories, + imageURL: [presignedUrl.mediaUrl], + }, + }); + return presignedUrl.mediaUrl; + }), + ); + } else { + postCoWorkingSpace.mutate({ + requestBody: { + title: values.title, + address: values.address, + mapsURL: values.mapsURL, + description: values.description, + location: values.location.map( + (c) => c.title, + ) as LocationCategories, + imageURL: pendingUpload ? [pendingUpload] : [], + }, + }); + } + } catch (err) { + console.log(err); + toast.error('Failed to post CoWorkingSpace', { id: TOAST_ID }); + } + }; + + return { categoryOptions, form, onSubmit, image, setImage }; +} + diff --git a/src/routes/_app/_left-navbar/home/rekomendasi/-useAddVoucher.ts b/src/routes/_app/_left-navbar/home/rekomendasi/-useAddVoucher.ts new file mode 100644 index 0000000..b35ea74 --- /dev/null +++ b/src/routes/_app/_left-navbar/home/rekomendasi/-useAddVoucher.ts @@ -0,0 +1,100 @@ +import { useState } from 'react'; +import { useLocationCategories } from './-useLocationCategories'; +import { useForm } from 'react-hook-form'; +import { VoucherSchema, VoucherSchemaType} from './-constants'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { useMutation } from '@tanstack/react-query'; +import { api, queryClient } from '~/api/client'; +import toast from 'react-hot-toast'; +import { PresignedURL } from '~/api/generated'; +import { FileUpload } from '../../add-announcement'; + +const TOAST_ID = 'add-voucher-toast'; + +type ComponentProps = { + onSubmitSuccess?: () => void; +}; + +export default function useVoucher(props: Readonly) { + const { onSubmitSuccess } = props; + + const [image, setImage] = useState(null); + const [pendingUpload, setPendingUpload] = useState(null); + const categoryOptions = useLocationCategories(); + + const form = useForm({ + resolver: zodResolver(VoucherSchema), + defaultValues: { + title: '', + imageURL: '', + link: '', + periodeAkhir: '', + periodeAwal: '', + description: '', + }, + }); + + const postVoucher = useMutation({ + mutationFn: api.recommendation.createVoucher.bind(api.recommendation), + onSuccess: () => { + toast.success('Voucher Posted!', { id: TOAST_ID }); + queryClient.invalidateQueries({ queryKey: ['voucher'] }); + setPendingUpload(''); + onSubmitSuccess?.(); + }, + onError: () => toast.error('Failed to post voucher', { id: TOAST_ID }), + }); + + const postMediaUpload = useMutation({ + mutationFn: api.media.createPresignedUrl.bind(api.media), + }); + + const onSubmit = async (values: VoucherSchemaType) => { + toast.loading('Please wait...', { id: TOAST_ID }); + + try { + if (!pendingUpload && image) { + const presignedUrl: PresignedURL = await postMediaUpload.mutateAsync({ + requestBody: { + fileName: image.file.name.split('.')[0], + fileType: image.file.name.split('.').at(-1) ?? '', + }, + }); + await fetch(presignedUrl.presignedUrl, { + method: 'PUT', + body: image.file, + }).then(() => + setPendingUpload(() => { + postVoucher.mutate({ + requestBody: { + title: values.title, + link: values.link, + periodeAkhir: values.periodeAkhir, + periodeAwal: values.periodeAwal, + imageURL: [presignedUrl.mediaUrl], + }, + }); + return presignedUrl.mediaUrl; + }), + ); + } else { + postVoucher.mutate({ + requestBody: { + title: values.title, + link: values.link, + periodeAwal: values.periodeAwal, + periodeAkhir: values.periodeAkhir, + description: values.description, + imageURL: pendingUpload ? [pendingUpload] : [], + }, + }); + } + } catch (err) { + console.log(err); + toast.error('Failed to post Voucher', { id: TOAST_ID }); + } + }; + + return { form, onSubmit, image, setImage }; +} + diff --git a/src/routes/_app/_left-navbar/home/rekomendasi/-useLocationCategories.ts b/src/routes/_app/_left-navbar/home/rekomendasi/-useLocationCategories.ts new file mode 100644 index 0000000..cb72cb8 --- /dev/null +++ b/src/routes/_app/_left-navbar/home/rekomendasi/-useLocationCategories.ts @@ -0,0 +1,19 @@ +import { useQuery } from '@tanstack/react-query'; + +export function useLocationCategories() { + const query = useQuery({ + queryKey: ['location-categories'], + queryFn: () => + Promise.resolve( + [ + { id: 'Ganesha', name: 'Ganesha Campus' }, + { id: 'Jatinangor', name: 'Jatinangor Campus' }, + ].map((c) => ({ + id: c.id, + title: `${c.name}`, + })), + ), + }); + + return query.data ?? []; +} From 0454b7bc9c9f62786d1dce6e410fa1db9cbe408e Mon Sep 17 00:00:00 2001 From: shika Date: Sat, 7 Dec 2024 20:06:27 +0700 Subject: [PATCH 02/10] feat: update rekomendasi form --- src/api/generated/index.ts | 1 - src/api/generated/models/CoWorking.ts | 3 +- src/api/generated/models/Voucher.ts | 6 +-- .../services/RecommendationService.ts | 33 +++++++------ src/assets/icons/rekomendasi/home.svg | 3 ++ .../custom-form/fields/MultiSelect.tsx | 2 +- .../custom-form/fields/SingleSelect.tsx | 2 +- .../-components/AddCoWorkingSpaceDialog.tsx | 46 ++++++++++--------- .../-components/AddCoWorkingSpaceDrawer.tsx | 32 +++++++------ .../-components/AddVoucherDialog.tsx | 7 ++- .../-components/AddVoucherDrawer.tsx | 7 ++- .../home/rekomendasi/-constants.ts | 37 ++++++--------- .../home/rekomendasi/-useAddCoWorkingSpace.ts | 31 ++++++------- .../home/rekomendasi/-useAddVoucher.ts | 18 ++++---- 14 files changed, 108 insertions(+), 120 deletions(-) create mode 100644 src/assets/icons/rekomendasi/home.svg diff --git a/src/api/generated/index.ts b/src/api/generated/index.ts index 322bca2..d8d86c4 100644 --- a/src/api/generated/index.ts +++ b/src/api/generated/index.ts @@ -24,7 +24,6 @@ export type { Competition } from './models/Competition'; export type { CompetitionCategories } from './models/CompetitionCategories'; export type { Voucher } from './models/Voucher'; export type { CoWorking } from './models/CoWorking'; -export type { LocationCategories } from './models/LocationCategories'; export type { Course } from './models/Course'; export type { Error } from './models/Error'; export type { Info } from './models/Info'; diff --git a/src/api/generated/models/CoWorking.ts b/src/api/generated/models/CoWorking.ts index 9a53e7e..7d51de7 100644 --- a/src/api/generated/models/CoWorking.ts +++ b/src/api/generated/models/CoWorking.ts @@ -2,11 +2,10 @@ /* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { LocationCategories } from './LocationCategories'; export type CoWorking = { title: string; imageUrl: string; - location: LocationCategories; + location: string; address: string; mapUrl: string; description: string | null; diff --git a/src/api/generated/models/Voucher.ts b/src/api/generated/models/Voucher.ts index 13c8e93..866e594 100644 --- a/src/api/generated/models/Voucher.ts +++ b/src/api/generated/models/Voucher.ts @@ -4,10 +4,10 @@ /* eslint-disable */ export type Voucher = { title: string; - imageUrl: string; + imageURL: string; link: string| null; - periodeAwal: string| null; - periodeAkhir: string| null; + startPeriod: string| null; + endPeriod: string| null; description: string | null; }; diff --git a/src/api/generated/services/RecommendationService.ts b/src/api/generated/services/RecommendationService.ts index c5d7921..14a9559 100644 --- a/src/api/generated/services/RecommendationService.ts +++ b/src/api/generated/services/RecommendationService.ts @@ -4,7 +4,6 @@ /* eslint-disable */ import type { Voucher } from '../models/Voucher'; import type { CoWorking } from '../models/CoWorking'; -import type { LocationCategories } from '../models/LocationCategories'; import type { CancelablePromise } from '../core/CancelablePromise'; import type { BaseHttpRequest } from '../core/BaseHttpRequest'; export class RecommendationService { @@ -18,8 +17,8 @@ export class RecommendationService { }: { requestBody?: { title: string; - imageURL: Array; - location: LocationCategories; + imageURL: string; + location: string; address: string; mapsURL: string; description?: string | null; @@ -47,7 +46,7 @@ export class RecommendationService { }> { return this.httpRequest.request({ method: 'POST', - url: '/api/rekomendasi/co-working-space', + url: '/api/recommendation/co-working-space', body: requestBody, mediaType: 'application/json', errors: { @@ -74,7 +73,7 @@ export class RecommendationService { }> { return this.httpRequest.request({ method: 'GET', - url: '/api/rekomendasi/co-working-space', + url: '/api/recommendation/co-working-space', query: { 'filter': filter, 'offset': offset, @@ -96,7 +95,7 @@ export class RecommendationService { requestBody?: { title?: string; imageURL?: Array; - location?: LocationCategories; + location?: string; address?: string; mapsURL?: string; description?: string | null; @@ -124,7 +123,7 @@ export class RecommendationService { }> { return this.httpRequest.request({ method: 'PUT', - url: '/api/rekomendasi/co-working-space/{id}', + url: '/api/recommendation/co-working-space/{id}', path: { 'id': id, }, @@ -150,7 +149,7 @@ export class RecommendationService { }): CancelablePromise { return this.httpRequest.request({ method: 'DELETE', - url: '/api/rekomendasi/co-working-space/{coWorkingSpaceId}', + url: '/api/recommendation/co-working-space/{coWorkingSpaceId}', path: { 'coWorkingSpaceId': coWorkingSpaceId, }, @@ -171,18 +170,18 @@ export class RecommendationService { }: { requestBody?: { title: string; - imageURL: Array; + imageURL: string; link: string; - periodeAwal?: string | null; - periodeAkhir?: string | null; + startPeriod?: string | null; + endPeriod?: string | null; description?: string | null; }, }): CancelablePromise<{ voucherId: string; title: string; link: string; - periodeAwal: string | null; - periodeAkhir: string | null; + startPeriod: string | null; + endPeriod: string | null; description: string | null imageURL: Array<{ voucherId: string; @@ -200,7 +199,7 @@ export class RecommendationService { }> { return this.httpRequest.request({ method: 'POST', - url: '/api/rekomendasi/voucher', + url: '/api/recommendation/voucher', body: requestBody, mediaType: 'application/json', errors: { @@ -227,7 +226,7 @@ export class RecommendationService { }> { return this.httpRequest.request({ method: 'GET', - url: '/api/rekomendasi/voucher', + url: '/api/recommendation/voucher', query: { 'filter': filter, 'offset': offset, @@ -277,7 +276,7 @@ export class RecommendationService { }> { return this.httpRequest.request({ method: 'PUT', - url: '/api/rekomendasi/voucher/{id}', + url: '/api/recommendation/voucher/{id}', path: { 'id': id, }, @@ -303,7 +302,7 @@ export class RecommendationService { }): CancelablePromise { return this.httpRequest.request({ method: 'DELETE', - url: '/api/rekomendasi/voucher/{voucherId}', + url: '/api/recommendation/voucher/{voucherId}', path: { 'voucherId': voucherId, }, diff --git a/src/assets/icons/rekomendasi/home.svg b/src/assets/icons/rekomendasi/home.svg new file mode 100644 index 0000000..700242f --- /dev/null +++ b/src/assets/icons/rekomendasi/home.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/components/custom-form/fields/MultiSelect.tsx b/src/components/custom-form/fields/MultiSelect.tsx index d650526..45c23f2 100644 --- a/src/components/custom-form/fields/MultiSelect.tsx +++ b/src/components/custom-form/fields/MultiSelect.tsx @@ -121,7 +121,7 @@ export default function MultiSelect( ...form.getValues(name), opt, // eslint-disable-next-line - ] as any); + ] as any); }} className="gap-2" key={idx} diff --git a/src/components/custom-form/fields/SingleSelect.tsx b/src/components/custom-form/fields/SingleSelect.tsx index 95db304..c8745db 100644 --- a/src/components/custom-form/fields/SingleSelect.tsx +++ b/src/components/custom-form/fields/SingleSelect.tsx @@ -79,7 +79,7 @@ export default function SingleSelect( value={opt.id} key={opt.id} // eslint-disable-next-line - onSelect={() => form.setValue(name, opt.id as any)} + onSelect={() => form.setValue(name, opt.id as any)} keywords={[opt.title]} className="cursor-pointer" > diff --git a/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddCoWorkingSpaceDialog.tsx b/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddCoWorkingSpaceDialog.tsx index cb002b8..79246f5 100644 --- a/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddCoWorkingSpaceDialog.tsx +++ b/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddCoWorkingSpaceDialog.tsx @@ -1,5 +1,5 @@ import { useEffect } from 'react'; -import CategoryIcon from '~/assets/icons/competition/category.svg'; +import HouseIcon from '~/assets/icons/rekomendasi/home.svg'; import ClockIcon from '~/assets/icons/clock.svg'; import DocsIcon from '~/assets/icons/rekomendasi/docs.svg'; import LinkIcon from '~/assets/icons/competition/link.svg'; @@ -17,15 +17,19 @@ type ComponentProps = { constraintRef: React.MutableRefObject; }; -export default function AddCoWorkingSpaceDialog(props: Readonly) { +export default function AddCoWorkingSpaceDialog( + props: Readonly, +) { const { isOpen, setOpen, constraintRef } = props; - - const { categoryOptions, form, onSubmit, image, setImage } = - useAddCoWorkingSpace({ - onSubmitSuccess: () => setOpen(false), - }); - + const options = [ + { id: 'Ganesha', title: 'Ganesha' }, + { id: 'Jatinangor', title: 'Jatinangor' }, + ]; + + const { form, onSubmit, image, setImage } = useAddCoWorkingSpace({ + onSubmitSuccess: () => setOpen(false), + }); useEffect(() => { if (!isOpen) { @@ -52,16 +56,15 @@ export default function AddCoWorkingSpaceDialog(props: Readonly) placeholder="Add Coworking Space Name" iconClassName="size-6 opacity-0" /> - ) iconClassName="size-6" /> - ) iconClassName="size-5" /> - - ) iconClassName="size-6" /> + ); } diff --git a/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddCoWorkingSpaceDrawer.tsx b/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddCoWorkingSpaceDrawer.tsx index f82ce1b..508e20d 100644 --- a/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddCoWorkingSpaceDrawer.tsx +++ b/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddCoWorkingSpaceDrawer.tsx @@ -1,8 +1,8 @@ import { useEffect } from 'react'; -import DocsIcon from '~/assets/icons/rekomendasi/docs.svg' import BookIcon from '~/assets/icons/calendar/book.svg'; import LinkIcon from '~/assets/icons/competition/link.svg'; import MarkerIcon from '~/assets/icons/rekomendasi/marker.svg'; +import HouseIcon from '~/assets/icons/rekomendasi/home.svg'; import Attachment from '~/components/custom-form/fields/Attachment'; import FormTextField from '~/components/custom-form/fields/FormTextField'; import MobileForm from '~/components/custom-form/MobileForm'; @@ -15,12 +15,16 @@ type ComponentProps = { }; export function AddCoWorkingSpaceDrawer(props: Readonly) { + const options = [ + { id: 'Ganesha', title: 'Ganesha' }, + { id: 'Jatinangor', title: 'Jatinangor' }, + ]; + const { isOpen, setOpen } = props; - const { categoryOptions, form, onSubmit, image, setImage } = - useAddCoWorkingSpace({ - onSubmitSuccess: () => setOpen(false), - }); + const { form, onSubmit, image, setImage } = useAddCoWorkingSpace({ + onSubmitSuccess: () => setOpen(false), + }); useEffect(() => { if (!isOpen) { @@ -40,14 +44,14 @@ export function AddCoWorkingSpaceDrawer(props: Readonly) { + form={form} + name="location" + options={options} + placeholder="Select Location" + icon={HouseIcon} + iconClassName="size-6" + className="py-4 lg:py-2" + /> ) { inputClassName="py-3 text-base" iconClassName="size-5" /> - ) { placeholder="Add Attachment" iconClassName="size-5 opacity-0" /> - ); } diff --git a/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddVoucherDialog.tsx b/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddVoucherDialog.tsx index 97bb986..d5577f4 100644 --- a/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddVoucherDialog.tsx +++ b/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddVoucherDialog.tsx @@ -18,10 +18,9 @@ type ComponentProps = { export default function AddVoucherDialog(props: Readonly) { const { isOpen, setOpen, constraintRef } = props; - const { form, onSubmit, image, setImage } = - useAddVoucher({ - onSubmitSuccess: () => setOpen(false), - }); + const { form, onSubmit, image, setImage } = useAddVoucher({ + onSubmitSuccess: () => setOpen(false), + }); useEffect(() => { if (!isOpen) { diff --git a/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddVoucherDrawer.tsx b/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddVoucherDrawer.tsx index acb86b8..bf476c8 100644 --- a/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddVoucherDrawer.tsx +++ b/src/routes/_app/_left-navbar/home/rekomendasi/-components/AddVoucherDrawer.tsx @@ -16,10 +16,9 @@ type ComponentProps = { export function AddVoucherDrawer(props: Readonly) { const { isOpen, setOpen } = props; - const {form, onSubmit, image, setImage } = - useAddVoucher({ - onSubmitSuccess: () => setOpen(false), - }); + const { form, onSubmit, image, setImage } = useAddVoucher({ + onSubmitSuccess: () => setOpen(false), + }); useEffect(() => { if (!isOpen) { diff --git a/src/routes/_app/_left-navbar/home/rekomendasi/-constants.ts b/src/routes/_app/_left-navbar/home/rekomendasi/-constants.ts index 0075388..f758a2b 100644 --- a/src/routes/_app/_left-navbar/home/rekomendasi/-constants.ts +++ b/src/routes/_app/_left-navbar/home/rekomendasi/-constants.ts @@ -8,31 +8,22 @@ export const VoucherSchema = z link: z.string().min(1), periodeAwal: z.string().datetime(), periodeAkhir: z.string().datetime(), - description: z.string().datetime(), + description: z.string(), }) - .refine( - (data) => isGreater(data.periodeAkhir, data.periodeAwal), - { - message: 'Voucher end date must be greater than the start date.', - path: ['voucherDeadline'], - }, - ); + .refine((data) => isGreater(data.periodeAkhir, data.periodeAwal), { + message: 'Voucher end date must be greater than the start date.', + path: ['voucherDeadline'], + }); export type VoucherSchemaType = z.infer; -export const CoWorkingSpaceSchema = z - .object({ - title: z.string().min(1), - imageURL: z.string(), - location: z - .object({ - id: z.string().min(1), - title: z.string().min(1), - }) - .array(), - address: z.string().min(1), - mapsURL: z.string(), - description: z.string().datetime(), - }); +export const CoWorkingSpaceSchema = z.object({ + title: z.string().min(1), + imageURL: z.string(), + location: z.string().min(1), + address: z.string().min(1), + mapsURL: z.string().min(1), + description: z.string().min(1), +}); -export type CoWorkingSpaceSchemaType = z.infer; \ No newline at end of file +export type CoWorkingSpaceSchemaType = z.infer; diff --git a/src/routes/_app/_left-navbar/home/rekomendasi/-useAddCoWorkingSpace.ts b/src/routes/_app/_left-navbar/home/rekomendasi/-useAddCoWorkingSpace.ts index 646d3fa..25e124c 100644 --- a/src/routes/_app/_left-navbar/home/rekomendasi/-useAddCoWorkingSpace.ts +++ b/src/routes/_app/_left-navbar/home/rekomendasi/-useAddCoWorkingSpace.ts @@ -1,12 +1,11 @@ import { useState } from 'react'; -import { useLocationCategories } from './-useLocationCategories'; import { useForm } from 'react-hook-form'; -import { CoWorkingSpaceSchema, CoWorkingSpaceSchemaType} from './-constants'; +import { CoWorkingSpaceSchema, CoWorkingSpaceSchemaType } from './-constants'; import { zodResolver } from '@hookform/resolvers/zod'; import { useMutation } from '@tanstack/react-query'; import { api, queryClient } from '~/api/client'; import toast from 'react-hot-toast'; -import { LocationCategories, PresignedURL } from '~/api/generated'; +import { PresignedURL } from '~/api/generated'; import { FileUpload } from '../../add-announcement'; const TOAST_ID = 'add-coworkingspace-toast'; @@ -20,14 +19,13 @@ export default function useAddCoWorkingSpace(props: Readonly) { const [image, setImage] = useState(null); const [pendingUpload, setPendingUpload] = useState(null); - const categoryOptions = useLocationCategories(); const form = useForm({ resolver: zodResolver(CoWorkingSpaceSchema), defaultValues: { title: '', imageURL: '', - location: [], + location: '', address: '', mapsURL: '', description: '', @@ -35,14 +33,17 @@ export default function useAddCoWorkingSpace(props: Readonly) { }); const postCoWorkingSpace = useMutation({ - mutationFn: api.recommendation.createCoWorkingSpace.bind(api.recommendation), + mutationFn: api.recommendation.createCoWorkingSpace.bind( + api.recommendation, + ), onSuccess: () => { toast.success('CoWorkingSpace Posted!', { id: TOAST_ID }); queryClient.invalidateQueries({ queryKey: ['coworkingspace'] }); setPendingUpload(''); onSubmitSuccess?.(); }, - onError: () => toast.error('Failed to post CoWorkingSpace', { id: TOAST_ID }), + onError: () => + toast.error('Failed to post CoWorkingSpace', { id: TOAST_ID }), }); const postMediaUpload = useMutation({ @@ -70,10 +71,9 @@ export default function useAddCoWorkingSpace(props: Readonly) { title: values.title, address: values.address, mapsURL: values.mapsURL, - location: values.location.map( - (c) => c.title, - ) as LocationCategories, - imageURL: [presignedUrl.mediaUrl], + description: values.description, + location: values.location, + imageURL: presignedUrl.mediaUrl, }, }); return presignedUrl.mediaUrl; @@ -86,10 +86,8 @@ export default function useAddCoWorkingSpace(props: Readonly) { address: values.address, mapsURL: values.mapsURL, description: values.description, - location: values.location.map( - (c) => c.title, - ) as LocationCategories, - imageURL: pendingUpload ? [pendingUpload] : [], + location: values.location, + imageURL: pendingUpload ? pendingUpload : '', }, }); } @@ -99,6 +97,5 @@ export default function useAddCoWorkingSpace(props: Readonly) { } }; - return { categoryOptions, form, onSubmit, image, setImage }; + return { form, onSubmit, image, setImage }; } - diff --git a/src/routes/_app/_left-navbar/home/rekomendasi/-useAddVoucher.ts b/src/routes/_app/_left-navbar/home/rekomendasi/-useAddVoucher.ts index b35ea74..893dcf3 100644 --- a/src/routes/_app/_left-navbar/home/rekomendasi/-useAddVoucher.ts +++ b/src/routes/_app/_left-navbar/home/rekomendasi/-useAddVoucher.ts @@ -1,7 +1,6 @@ import { useState } from 'react'; -import { useLocationCategories } from './-useLocationCategories'; import { useForm } from 'react-hook-form'; -import { VoucherSchema, VoucherSchemaType} from './-constants'; +import { VoucherSchema, VoucherSchemaType } from './-constants'; import { zodResolver } from '@hookform/resolvers/zod'; import { useMutation } from '@tanstack/react-query'; import { api, queryClient } from '~/api/client'; @@ -20,7 +19,6 @@ export default function useVoucher(props: Readonly) { const [image, setImage] = useState(null); const [pendingUpload, setPendingUpload] = useState(null); - const categoryOptions = useLocationCategories(); const form = useForm({ resolver: zodResolver(VoucherSchema), @@ -69,9 +67,10 @@ export default function useVoucher(props: Readonly) { requestBody: { title: values.title, link: values.link, - periodeAkhir: values.periodeAkhir, - periodeAwal: values.periodeAwal, - imageURL: [presignedUrl.mediaUrl], + endPeriod: values.periodeAkhir, + startPeriod: values.periodeAwal, + description: values.description, + imageURL: presignedUrl.mediaUrl, }, }); return presignedUrl.mediaUrl; @@ -82,10 +81,10 @@ export default function useVoucher(props: Readonly) { requestBody: { title: values.title, link: values.link, - periodeAwal: values.periodeAwal, - periodeAkhir: values.periodeAkhir, + startPeriod: values.periodeAwal, + endPeriod: values.periodeAkhir, description: values.description, - imageURL: pendingUpload ? [pendingUpload] : [], + imageURL: pendingUpload ? pendingUpload : '', }, }); } @@ -97,4 +96,3 @@ export default function useVoucher(props: Readonly) { return { form, onSubmit, image, setImage }; } - From aab330ff116baa81e830ab25f21f9576c1288a28 Mon Sep 17 00:00:00 2001 From: debrinashika <118027372+debrinashika@users.noreply.github.com> Date: Sat, 7 Dec 2024 20:22:41 +0700 Subject: [PATCH 03/10] Update ApiClient.ts --- src/api/generated/ApiClient.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/api/generated/ApiClient.ts b/src/api/generated/ApiClient.ts index e02700f..5797b68 100644 --- a/src/api/generated/ApiClient.ts +++ b/src/api/generated/ApiClient.ts @@ -19,7 +19,6 @@ import { MediaService } from './services/MediaService'; import { OpenGraphService } from './services/OpenGraphService'; import { PushService } from './services/PushService'; import { ReactionService } from './services/ReactionService'; -import { RecommendationService } from './services/RecommendationService'; import { TestimoniService } from './services/TestimoniService'; import { UnsubscribeService } from './services/UnsubscribeService'; import { UserFinderService } from './services/UserFinderService'; @@ -73,7 +72,6 @@ export class ApiClient { this.openGraph = new OpenGraphService(this.request); this.push = new PushService(this.request); this.reaction = new ReactionService(this.request); - this.recommendation = new RecommendationService(this.request); this.testimoni = new TestimoniService(this.request); this.unsubscribe = new UnsubscribeService(this.request); this.userFinder = new UserFinderService(this.request); From c4ffb6925fdd154bc8d9b590c4bc733042956904 Mon Sep 17 00:00:00 2001 From: debrinashika <118027372+debrinashika@users.noreply.github.com> Date: Sat, 7 Dec 2024 20:24:26 +0700 Subject: [PATCH 04/10] Update ApiClient.ts --- src/api/generated/ApiClient.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/api/generated/ApiClient.ts b/src/api/generated/ApiClient.ts index 5797b68..08a0970 100644 --- a/src/api/generated/ApiClient.ts +++ b/src/api/generated/ApiClient.ts @@ -40,7 +40,6 @@ export class ApiClient { public readonly openGraph: OpenGraphService; public readonly push: PushService; public readonly reaction: ReactionService; - public readonly recommendation: RecommendationService; public readonly testimoni: TestimoniService; public readonly unsubscribe: UnsubscribeService; public readonly userFinder: UserFinderService; From 748834bb6f2917a4ab42a062e137e42dab4d2b9c Mon Sep 17 00:00:00 2001 From: debrinashika <118027372+debrinashika@users.noreply.github.com> Date: Sat, 7 Dec 2024 20:26:45 +0700 Subject: [PATCH 05/10] Update index.tsx --- src/routes/_app/_left-navbar/add-announcement/index.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/routes/_app/_left-navbar/add-announcement/index.tsx b/src/routes/_app/_left-navbar/add-announcement/index.tsx index f0d86fd..794f846 100644 --- a/src/routes/_app/_left-navbar/add-announcement/index.tsx +++ b/src/routes/_app/_left-navbar/add-announcement/index.tsx @@ -84,7 +84,7 @@ export function AddAnnouncementPage({ const mobileHandleSuccess = () => navigate({ to: '/timeline' }); const desktopHandleSuccess = () => - navigate({ search: (prev) => ({ ...prev, showAnnounce: undefined }) }); + navigate({ search: (prev:any) => ({ ...prev, showAnnounce: undefined }) }); const postInfo = useMutation({ mutationFn: api.info.createInfo.bind(api.info), @@ -155,10 +155,10 @@ export function AddAnnouncementPage({ const deleteById = (images: boolean, idx: number) => { images - ? setImages((prev) => { + ? setImages((prev:any) => { return prev.filter((image, index) => index !== idx); }) - : setFiles((prev) => { + : setFiles((prev:any => { return prev.filter((file, index) => index !== idx); }); }; From 9ec332ca9ba7480c6f732650c8822c37a80d327c Mon Sep 17 00:00:00 2001 From: debrinashika <118027372+debrinashika@users.noreply.github.com> Date: Sat, 7 Dec 2024 20:29:23 +0700 Subject: [PATCH 06/10] Update index.tsx --- src/routes/_app/_left-navbar/add-announcement/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/_app/_left-navbar/add-announcement/index.tsx b/src/routes/_app/_left-navbar/add-announcement/index.tsx index 794f846..a58a3d0 100644 --- a/src/routes/_app/_left-navbar/add-announcement/index.tsx +++ b/src/routes/_app/_left-navbar/add-announcement/index.tsx @@ -158,7 +158,7 @@ export function AddAnnouncementPage({ ? setImages((prev:any) => { return prev.filter((image, index) => index !== idx); }) - : setFiles((prev:any => { + : setFiles((prev:any) => { return prev.filter((file, index) => index !== idx); }); }; From 75d155f57bf95ade9bbcd15029f5a566fa289773 Mon Sep 17 00:00:00 2001 From: shika Date: Sat, 7 Dec 2024 20:39:15 +0700 Subject: [PATCH 07/10] fic: pnpm lint --- src/routes/_app/_left-navbar/add-announcement/index.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/routes/_app/_left-navbar/add-announcement/index.tsx b/src/routes/_app/_left-navbar/add-announcement/index.tsx index a58a3d0..f0d86fd 100644 --- a/src/routes/_app/_left-navbar/add-announcement/index.tsx +++ b/src/routes/_app/_left-navbar/add-announcement/index.tsx @@ -84,7 +84,7 @@ export function AddAnnouncementPage({ const mobileHandleSuccess = () => navigate({ to: '/timeline' }); const desktopHandleSuccess = () => - navigate({ search: (prev:any) => ({ ...prev, showAnnounce: undefined }) }); + navigate({ search: (prev) => ({ ...prev, showAnnounce: undefined }) }); const postInfo = useMutation({ mutationFn: api.info.createInfo.bind(api.info), @@ -155,10 +155,10 @@ export function AddAnnouncementPage({ const deleteById = (images: boolean, idx: number) => { images - ? setImages((prev:any) => { + ? setImages((prev) => { return prev.filter((image, index) => index !== idx); }) - : setFiles((prev:any) => { + : setFiles((prev) => { return prev.filter((file, index) => index !== idx); }); }; From 697c60bd35db733c9072a5d9bff4ab785800686f Mon Sep 17 00:00:00 2001 From: shika Date: Tue, 17 Dec 2024 21:37:16 +0700 Subject: [PATCH 08/10] fix: recommendation form --- src/api/generated/services/RecommendationService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/generated/services/RecommendationService.ts b/src/api/generated/services/RecommendationService.ts index 7c96ed6..17c1a79 100644 --- a/src/api/generated/services/RecommendationService.ts +++ b/src/api/generated/services/RecommendationService.ts @@ -236,4 +236,4 @@ export class RecommendationService { }, }); } - /** \ No newline at end of file +} \ No newline at end of file From 236351367561d2b8d8681dc4263ed38ea8919bda Mon Sep 17 00:00:00 2001 From: shika Date: Tue, 17 Dec 2024 22:13:34 +0700 Subject: [PATCH 09/10] fix: update tsconfig. --- tsconfig.json | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index 4453ae1..50a4a12 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,12 +2,7 @@ "compilerOptions": { "target": "ES2020", "useDefineForClassFields": true, - "lib": [ - "ES2020", - "DOM", - "DOM.Iterable", - "WebWorker" - ], + "lib": ["ES2020", "DOM", "DOM.Iterable", "WebWorker"], "module": "ESNext", "skipLibCheck": true, /* Bundler mode */ @@ -22,19 +17,16 @@ "noUnusedLocals": false, "noUnusedParameters": false, "noFallthroughCasesInSwitch": true, + "noImplicitAny": false, "paths": { - "~/*": [ - "src/*" - ], + "~/*": ["src/*"] }, "baseUrl": "." }, - "include": [ - "src" - ], + "include": ["src"], "references": [ { "path": "./tsconfig.node.json" } ] -} \ No newline at end of file +} From 5ec23117cd669e0909639036809b4b22442e6659 Mon Sep 17 00:00:00 2001 From: shika Date: Tue, 17 Dec 2024 22:20:31 +0700 Subject: [PATCH 10/10] update tsconfig again --- tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 50a4a12..9072caa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,6 @@ "noUnusedLocals": false, "noUnusedParameters": false, "noFallthroughCasesInSwitch": true, - "noImplicitAny": false, "paths": { "~/*": ["src/*"] },