From d206ae3b9686e1096bf77dc2a8e45982e3dd9c3b Mon Sep 17 00:00:00 2001 From: Pjaijai <87293994+Pjaijai@users.noreply.github.com> Date: Wed, 8 May 2024 21:24:58 -0400 Subject: [PATCH] Feature/request count for post and user (#368) * style: update style * feat: replace FormTextInput with FormTextArea * feat: add count * fix: reset submit state when error in edit post * feat: update types --------- Co-authored-by: Pjaijai --- .../chat/components/forms/message/message.tsx | 4 +- client/modules/main/template.tsx | 4 +- client/modules/post/edit/template.tsx | 3 +- client/types/supabase.ts | 186 ++++++++++++++++-- .../functions/message-post-creator/index.ts | 9 +- supabase/functions/message-referral/index.ts | 10 +- .../20240508234834_creat_count_for_user.sql | 7 + .../20240509011018_creat_count_for_post.sql | 6 + 8 files changed, 206 insertions(+), 23 deletions(-) create mode 100644 supabase/migrations/20240508234834_creat_count_for_user.sql create mode 100644 supabase/migrations/20240509011018_creat_count_for_post.sql diff --git a/client/modules/chat/components/forms/message/message.tsx b/client/modules/chat/components/forms/message/message.tsx index 95bd12af..b76abf14 100644 --- a/client/modules/chat/components/forms/message/message.tsx +++ b/client/modules/chat/components/forms/message/message.tsx @@ -17,7 +17,7 @@ import useGetMediaPublicUrl from "@/hooks/api/storage/get-media-url" import useUserStore from "@/hooks/state/user/store" import { Form } from "@/components/ui/form" import { useToast } from "@/components/ui/use-toast" -import FormTextInput from "@/components/customized-ui/form/input" +import FormTextArea from "@/components/customized-ui/form/text-area" import { Icons } from "@/components/icons" interface ISendMessageFormProps { @@ -235,7 +235,7 @@ const SendMessageForm: React.FunctionComponent = ({ )}
- -
+
-
+
diff --git a/client/modules/post/edit/template.tsx b/client/modules/post/edit/template.tsx index b7e08f2e..c4681220 100644 --- a/client/modules/post/edit/template.tsx +++ b/client/modules/post/edit/template.tsx @@ -5,7 +5,7 @@ import { useRouter } from "next/navigation" import usePostTypeOptions from "@/modules/post/hooks/post-type-options" import { useI18n } from "@/utils/services/internationalization/client" import { zodResolver } from "@hookform/resolvers/zod" -import { useForm } from "react-hook-form" +import { set, useForm } from "react-hook-form" import { z } from "zod" import { ICityResponse } from "@/types/api/response/city" @@ -249,6 +249,7 @@ const EditPostPageTemplate: React.FunctionComponent< router.push(`${siteConfig.page.viewPost.href}/${postUuid}`) }, onError: () => { + setIsSubmitting(false) return toast({ title: t("general.error.title"), description: t("general.error.description"), diff --git a/client/types/supabase.ts b/client/types/supabase.ts index 3ec19a26..dbd82052 100644 --- a/client/types/supabase.ts +++ b/client/types/supabase.ts @@ -6,7 +6,7 @@ export type Json = | { [key: string]: Json | undefined } | Json[] -export interface Database { +export type Database = { graphql_public: { Tables: { [_ in never]: never @@ -239,6 +239,7 @@ export interface Database { Row: { city_uuid: string | null company_name: string | null + contact_request_count: number country_uuid: string | null created_at: string | null created_by: string | null @@ -256,6 +257,7 @@ export interface Database { Insert: { city_uuid?: string | null company_name?: string | null + contact_request_count?: number country_uuid?: string | null created_at?: string | null created_by?: string | null @@ -273,6 +275,7 @@ export interface Database { Update: { city_uuid?: string | null company_name?: string | null + contact_request_count?: number country_uuid?: string | null created_at?: string | null created_by?: string | null @@ -330,6 +333,7 @@ export interface Database { created_at: string | null id: number message: string | null + message_uuid: string | null post_uuid: string | null sender_uuid: string | null type: string | null @@ -339,6 +343,7 @@ export interface Database { created_at?: string | null id?: number message?: string | null + message_uuid?: string | null post_uuid?: string | null sender_uuid?: string | null type?: string | null @@ -348,12 +353,20 @@ export interface Database { created_at?: string | null id?: number message?: string | null + message_uuid?: string | null post_uuid?: string | null sender_uuid?: string | null type?: string | null uuid?: string | null } Relationships: [ + { + foreignKeyName: "post_contact_history_message_uuid_fkey" + columns: ["message_uuid"] + isOneToOne: false + referencedRelation: "message" + referencedColumns: ["uuid"] + }, { foreignKeyName: "post_contact_history_post_uuid_fkey" columns: ["post_uuid"] @@ -402,6 +415,7 @@ export interface Database { created_at: string | null id: number message: string | null + message_uuid: string | null receiver_uuid: string | null sender_uuid: string | null type: string | null @@ -411,6 +425,7 @@ export interface Database { created_at?: string | null id?: number message?: string | null + message_uuid?: string | null receiver_uuid?: string | null sender_uuid?: string | null type?: string | null @@ -420,12 +435,20 @@ export interface Database { created_at?: string | null id?: number message?: string | null + message_uuid?: string | null receiver_uuid?: string | null sender_uuid?: string | null type?: string | null uuid?: string | null } Relationships: [ + { + foreignKeyName: "referral_contact_history_message_uuid_fkey" + columns: ["message_uuid"] + isOneToOne: false + referencedRelation: "message" + referencedColumns: ["uuid"] + }, { foreignKeyName: "referral_contact_history_receiver_uuid_fkey" columns: ["receiver_uuid"] @@ -447,6 +470,7 @@ export interface Database { avatar_url: string | null city_uuid: string | null company_name: string | null + contact_request_count: number country_uuid: string | null created_at: string | null description: string | null @@ -469,6 +493,7 @@ export interface Database { avatar_url?: string | null city_uuid?: string | null company_name?: string | null + contact_request_count?: number country_uuid?: string | null created_at?: string | null description?: string | null @@ -491,6 +516,7 @@ export interface Database { avatar_url?: string | null city_uuid?: string | null company_name?: string | null + contact_request_count?: number country_uuid?: string | null created_at?: string | null description?: string | null @@ -698,6 +724,101 @@ export interface Database { }, ] } + s3_multipart_uploads: { + Row: { + bucket_id: string + created_at: string + id: string + in_progress_size: number + key: string + owner_id: string | null + upload_signature: string + version: string + } + Insert: { + bucket_id: string + created_at?: string + id: string + in_progress_size?: number + key: string + owner_id?: string | null + upload_signature: string + version: string + } + Update: { + bucket_id?: string + created_at?: string + id?: string + in_progress_size?: number + key?: string + owner_id?: string | null + upload_signature?: string + version?: string + } + Relationships: [ + { + foreignKeyName: "s3_multipart_uploads_bucket_id_fkey" + columns: ["bucket_id"] + isOneToOne: false + referencedRelation: "buckets" + referencedColumns: ["id"] + }, + ] + } + s3_multipart_uploads_parts: { + Row: { + bucket_id: string + created_at: string + etag: string + id: string + key: string + owner_id: string | null + part_number: number + size: number + upload_id: string + version: string + } + Insert: { + bucket_id: string + created_at?: string + etag: string + id?: string + key: string + owner_id?: string | null + part_number: number + size?: number + upload_id: string + version: string + } + Update: { + bucket_id?: string + created_at?: string + etag?: string + id?: string + key?: string + owner_id?: string | null + part_number?: number + size?: number + upload_id?: string + version?: string + } + Relationships: [ + { + foreignKeyName: "s3_multipart_uploads_parts_bucket_id_fkey" + columns: ["bucket_id"] + isOneToOne: false + referencedRelation: "buckets" + referencedColumns: ["id"] + }, + { + foreignKeyName: "s3_multipart_uploads_parts_upload_id_fkey" + columns: ["upload_id"] + isOneToOne: false + referencedRelation: "s3_multipart_uploads" + referencedColumns: ["id"] + }, + ] + } } Views: { [_ in never]: never @@ -728,7 +849,7 @@ export interface Database { Args: { name: string } - Returns: unknown + Returns: string[] } get_size_by_bucket: { Args: Record @@ -737,6 +858,37 @@ export interface Database { bucket_id: string }[] } + list_multipart_uploads_with_delimiter: { + Args: { + bucket_id: string + prefix_param: string + delimiter_param: string + max_keys?: number + next_key_token?: string + next_upload_token?: string + } + Returns: { + key: string + id: string + created_at: string + }[] + } + list_objects_with_delimiter: { + Args: { + bucket_id: string + prefix_param: string + delimiter_param: string + max_keys?: number + start_after?: string + next_token?: string + } + Returns: { + name: string + id: string + metadata: Json + updated_at: string + }[] + } search: { Args: { prefix: string @@ -767,9 +919,11 @@ export interface Database { } } +type PublicSchema = Database[Extract] + export type Tables< PublicTableNameOrOptions extends - | keyof (Database["public"]["Tables"] & Database["public"]["Views"]) + | keyof (PublicSchema["Tables"] & PublicSchema["Views"]) | { schema: keyof Database }, TableName extends PublicTableNameOrOptions extends { schema: keyof Database } ? keyof (Database[PublicTableNameOrOptions["schema"]]["Tables"] & @@ -782,10 +936,10 @@ export type Tables< } ? R : never - : PublicTableNameOrOptions extends keyof (Database["public"]["Tables"] & - Database["public"]["Views"]) - ? (Database["public"]["Tables"] & - Database["public"]["Views"])[PublicTableNameOrOptions] extends { + : PublicTableNameOrOptions extends keyof (PublicSchema["Tables"] & + PublicSchema["Views"]) + ? (PublicSchema["Tables"] & + PublicSchema["Views"])[PublicTableNameOrOptions] extends { Row: infer R } ? R @@ -794,7 +948,7 @@ export type Tables< export type TablesInsert< PublicTableNameOrOptions extends - | keyof Database["public"]["Tables"] + | keyof PublicSchema["Tables"] | { schema: keyof Database }, TableName extends PublicTableNameOrOptions extends { schema: keyof Database } ? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"] @@ -805,8 +959,8 @@ export type TablesInsert< } ? I : never - : PublicTableNameOrOptions extends keyof Database["public"]["Tables"] - ? Database["public"]["Tables"][PublicTableNameOrOptions] extends { + : PublicTableNameOrOptions extends keyof PublicSchema["Tables"] + ? PublicSchema["Tables"][PublicTableNameOrOptions] extends { Insert: infer I } ? I @@ -815,7 +969,7 @@ export type TablesInsert< export type TablesUpdate< PublicTableNameOrOptions extends - | keyof Database["public"]["Tables"] + | keyof PublicSchema["Tables"] | { schema: keyof Database }, TableName extends PublicTableNameOrOptions extends { schema: keyof Database } ? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"] @@ -826,8 +980,8 @@ export type TablesUpdate< } ? U : never - : PublicTableNameOrOptions extends keyof Database["public"]["Tables"] - ? Database["public"]["Tables"][PublicTableNameOrOptions] extends { + : PublicTableNameOrOptions extends keyof PublicSchema["Tables"] + ? PublicSchema["Tables"][PublicTableNameOrOptions] extends { Update: infer U } ? U @@ -836,13 +990,13 @@ export type TablesUpdate< export type Enums< PublicEnumNameOrOptions extends - | keyof Database["public"]["Enums"] + | keyof PublicSchema["Enums"] | { schema: keyof Database }, EnumName extends PublicEnumNameOrOptions extends { schema: keyof Database } ? keyof Database[PublicEnumNameOrOptions["schema"]]["Enums"] : never = never, > = PublicEnumNameOrOptions extends { schema: keyof Database } ? Database[PublicEnumNameOrOptions["schema"]]["Enums"][EnumName] - : PublicEnumNameOrOptions extends keyof Database["public"]["Enums"] - ? Database["public"]["Enums"][PublicEnumNameOrOptions] + : PublicEnumNameOrOptions extends keyof PublicSchema["Enums"] + ? PublicSchema["Enums"][PublicEnumNameOrOptions] : never diff --git a/supabase/functions/message-post-creator/index.ts b/supabase/functions/message-post-creator/index.ts index 952be26d..385ba603 100644 --- a/supabase/functions/message-post-creator/index.ts +++ b/supabase/functions/message-post-creator/index.ts @@ -71,7 +71,8 @@ serve(async (req: any) => { job_title, description, url, - uuid + uuid, + contact_request_count `, ) .eq("uuid", post_uuid) @@ -192,6 +193,12 @@ serve(async (req: any) => { message_uuid: messageUuid, }) + const { data: updatePostCount } = await server + .from("post") + .update({ contact_request_count: post.contact_request_count + 1 }) + .eq("uuid", post.uuid) + .single() + const subject = `${sender.username} is interested in you post - ${post.job_title}` const body = ` diff --git a/supabase/functions/message-referral/index.ts b/supabase/functions/message-referral/index.ts index 60a2e570..32c32b0d 100644 --- a/supabase/functions/message-referral/index.ts +++ b/supabase/functions/message-referral/index.ts @@ -59,7 +59,9 @@ serve(async (req: any) => { const { data: receiver } = await server .from("user") - .select("uuid, email,username, is_referer ,is_referee") + .select( + "uuid, email,username, is_referer ,is_referee,contact_request_count ", + ) .eq("uuid", to_uuid) .single() @@ -167,6 +169,12 @@ serve(async (req: any) => { message_uuid: messageUuid, }) + const { data: updateReceiverCount } = await server + .from("user") + .update({ contact_request_count: receiver.contact_request_count + 1 }) + .eq("uuid", to_uuid) + .single() + const subject = `${sender.username} sent you a message.` const emailBody = ` diff --git a/supabase/migrations/20240508234834_creat_count_for_user.sql b/supabase/migrations/20240508234834_creat_count_for_user.sql new file mode 100644 index 00000000..2def32d9 --- /dev/null +++ b/supabase/migrations/20240508234834_creat_count_for_user.sql @@ -0,0 +1,7 @@ +revoke update on table "public"."user" from "authenticated"; + +GRANT UPDATE (username, avatar_url, city_uuid, company_name, country_uuid, description, job_title, province_uuid, year_of_experience, social_media_url, industry_uuid, is_referee, is_referer) ON "public"."user" TO "authenticated"; + +alter table "public"."user" add column "contact_request_count" smallint not null default '0'::smallint; + + diff --git a/supabase/migrations/20240509011018_creat_count_for_post.sql b/supabase/migrations/20240509011018_creat_count_for_post.sql new file mode 100644 index 00000000..bb89f6a4 --- /dev/null +++ b/supabase/migrations/20240509011018_creat_count_for_post.sql @@ -0,0 +1,6 @@ +revoke update on table "public"."post" from "authenticated"; +GRANT UPDATE (status, url, country_uuid, province_uuid,city_uuid, industry_uuid,year_of_experience,created_by ,type,company_name,job_title,description) ON public.post TO authenticated; + +alter table "public"."post" add column "contact_request_count" smallint not null default '0'::smallint; + +