From 06fa3ab9ac036dc4e12672c59994344b98684521 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 10 Apr 2024 20:12:41 +0700 Subject: [PATCH] refactor: adjust image upload These fields are required but is not strictly validate at api level. API will return presigned url so that client can upload file to storage. --- src/stores/branch-contact/index.ts | 15 ++++++++------- src/stores/user/index.ts | 13 +++++++------ src/stores/user/types.ts | 18 +++++++++--------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/stores/branch-contact/index.ts b/src/stores/branch-contact/index.ts index 1fe82acc..dbdb7fc9 100644 --- a/src/stores/branch-contact/index.ts +++ b/src/stores/branch-contact/index.ts @@ -50,7 +50,7 @@ const useBranchContactStore = defineStore('api-branch-contact', () => { async function create( branchId: string, data: BranchContactCreate, - qrCodeImage: File, + qrCodeImage?: File | null, // required but not strict flow?: { sessionId: string; refTransactionId: string; @@ -69,12 +69,13 @@ const useBranchContactStore = defineStore('api-branch-contact', () => { }, }); - await axios - .put(res.data.qrCodeImageUploadUrl, qrCodeImage, { - headers: { 'Content-Type': qrCodeImage.type }, - onUploadProgress: (e) => console.log(e), - }) - .catch((e) => console.error(e)); + qrCodeImage && + (await axios + .put(res.data.qrCodeImageUploadUrl, qrCodeImage, { + headers: { 'Content-Type': qrCodeImage.type }, + onUploadProgress: (e) => console.log(e), + }) + .catch((e) => console.error(e))); if (!res) return false; diff --git a/src/stores/user/index.ts b/src/stores/user/index.ts index 657359b8..4b45c31b 100644 --- a/src/stores/user/index.ts +++ b/src/stores/user/index.ts @@ -206,12 +206,13 @@ const useUserStore = defineStore('api-user', () => { }, ); - await axios - .put(res.data.profileImageUploadUrl, profileImage, { - headers: { 'Content-Type': profileImage.type }, - onUploadProgress: (e) => console.log(e), - }) - .catch((e) => console.error(e)); + profileImage && + (await axios + .put(res.data.profileImageUploadUrl, profileImage, { + headers: { 'Content-Type': profileImage.type }, + onUploadProgress: (e) => console.log(e), + }) + .catch((e) => console.error(e))); if (!res) return false; diff --git a/src/stores/user/types.ts b/src/stores/user/types.ts index 044d389a..c17d8d1a 100644 --- a/src/stores/user/types.ts +++ b/src/stores/user/types.ts @@ -41,8 +41,8 @@ export type User = { profileImageUrl: string; code: string; birthDate?: Date | null; - responsibleArea: string, - branch: Branch[] + responsibleArea: string; + branch: Branch[]; }; export type UserCreate = { @@ -72,9 +72,9 @@ export type UserCreate = { userRole: string; userType: string; keycloakId: string; - profileImage: File; + profileImage?: File | null; // required but not strict birthDate?: Date | null; - responsibleArea: string, + responsibleArea: string; }; export type UserAttachment = { @@ -95,14 +95,14 @@ export type UserTypeStats = { MESSENGER: number; DELEGATE: number; AGENCY: number; -} +}; export type UserOption = { - hqOpts: Option[] - brOpts: Option[] -} + hqOpts: Option[]; + brOpts: Option[]; +}; export type Option = { label: string; value: string; -} +};