feat: userOption

This commit is contained in:
puriphatt 2024-04-11 15:05:01 +07:00
parent 0206372cef
commit 81b74ebe5d
3 changed files with 117 additions and 82 deletions

View file

@ -3,18 +3,77 @@ import { defineStore } from 'pinia';
import { Pagination } from '../types';
import { api } from 'src/boot/axios';
import {
RoleData,
User,
UserAttachment,
UserAttachmentCreate,
UserAttachmentDelete,
UserCreate,
UserOption,
} from './types';
import axios from 'axios';
import { Branch } from '../branch/types';
const useUserStore = defineStore('api-user', () => {
const userOption = ref<UserOption>({
hqOpts: [],
brOpts: [],
roleOpts: [],
userTypeOpts: [
{ label: 'พนักงาน', value: 'USER' },
{ label: 'พนักงานส่งเอกสาร', value: 'MESSENGER' },
{ label: 'ตัวแทน', value: 'DELEGATE' },
{ label: 'เอเจนซี่', value: 'AGENCY' },
],
genderOpts: [
{ label: 'ชาย', value: 'male' },
{ label: 'หญิง', value: 'female' },
],
responsibleAreaOpts: [
{ label: 'เขตพื้นที่ 1 บางรัก ปทุมวัน ยานนาวสาทร และบางคอแหลม' },
{ label: 'เขตพื้นที่ 2 จอมทอง ทุ่งครุ บางขุนเทียน บางบอน และราษฎร์บูรณะ' },
{ label: 'เขตพื้นที่ 3 คลองเตย บางนา ประเวศ พระโขนง วัฒนา และสวนหลวง' },
{ label: 'เขตพื้นที่ 4 คันนายาว บางกะปิ ลาดพร้าว บึงกุ่ม และวังทางหลาง' },
{ label: 'เขตพื้นที่ 5 คลองสามวา มีนบุรี ลาดกระบัง สะพานสูง หนองจอก และสายไหม' },
{ label: 'เขตพื้นที่ 6 คลองสาน ธนบุรี บางกอกน้อย บางกอกใหญ่ และบางพลัด' },
{ label: 'เขตพื้นที่ 7 ตลิ่งชัน ทวีวัฒนา บางแค ภาษีเจริญ และหนองแขม' },
{ label: 'เขตพื้นที่ 8 ดุสิต พระนครป้อมปราบศัตรูพ่าย และสัมพันธวงศ์' },
{ label: 'เขตพื้นที่ 9 จตุจักร ดอนเมือง บางชื่อ บางเขน และหลักส' },
{ label: 'เขตพื้นที่ 10 ดินแดง พญาไท ราชเทวี และห้วยขวาง' },
],
nationalityOpts: [
{ label: 'ไทย', value: 'th' },
{ label: 'เมียนมา', value: 'mm' },
{ label: 'ลาว', value: 'lo' },
{ label: 'กัมพูชา', value: 'kh' },
{ label: 'เวียดนาม', value: 'vn' },
],
trainingPlaceOpts: [
{ label: 'สถานที่อบรมแรงงานเมียนมา-แม่สอด จ.ตาก' },
{ label: 'สถานที่อบรมแรงงานเมียนมา- เกาะสอง จ.ระนอง' },
{ label: 'สถานที่อบรมแรงงานลาว-หนองคาย จ.หนองคาย' },
{ label: 'สถานที่อบรมแรงงานกัมพูชา- อรัญประเทศ จ.สระแก้ว' },
{ label: 'สถานที่อบรมแรงงานกัมพูชา-บ้านแหลม จ.จันทบุร' },
],
});
const data = ref<Pagination<User[]>>();
async function fetchRoleOption() {
const res = await api.get<RoleData[]>('/keycloak/role');
res.data.map((item) => {
const formattedName = item.name
.replace(/_/g, ' ')
.toLowerCase()
.split(' ')
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ');
userOption.value.roleOpts.push({
label: formattedName,
value: item.id,
});
});
}
async function fetchAttachment(
userId: string,
flow?: {
@ -228,9 +287,10 @@ const useUserStore = defineStore('api-user', () => {
transactionId: string;
},
) {
const { profileImage, ...payload } = data
const res = await api.put<User & { profileImageUploadUrl: string }>(
`/user/${id}`,
data,
payload,
{
headers: {
'X-Session-Id': flow?.sessionId,
@ -240,10 +300,10 @@ const useUserStore = defineStore('api-user', () => {
},
);
if (data.profileImage)
if (profileImage)
await axios
.put(res.data.profileImageUploadUrl, data.profileImage, {
headers: { 'Content-Type': data.profileImage.type },
.put(res.data.profileImageUploadUrl, profileImage, {
headers: { 'Content-Type': profileImage.type },
onUploadProgress: (e) => console.log(e),
})
.catch((e) => console.error(e));
@ -368,6 +428,9 @@ const useUserStore = defineStore('api-user', () => {
return {
data,
userOption,
fetchRoleOption,
fetchList,
fetchById,

View file

@ -100,12 +100,17 @@ export type UserTypeStats = {
export type UserOption = {
hqOpts: Option[];
brOpts: Option[];
genderOpts: Option[];
userTypeOpts: Option[];
roleOpts: Option[];
responsibleAreaOpts: Option[];
nationalityOpts: Option[];
trainingPlaceOpts: Option[];
};
export type Option = {
label: string;
value: string;
value?: string;
};
export type RoleData = {