init: SR System — Helpdesk & ITAM Portal
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import commonCodeService from '@/services/commonCodeService';
|
||||
|
||||
interface CodeItem {
|
||||
codeValue: string;
|
||||
codeName: string;
|
||||
sortOrder: number;
|
||||
}
|
||||
|
||||
export function useCommonCodes(groupCode: string): { codes: CodeItem[]; loading: boolean } {
|
||||
const [codes, setCodes] = useState<CodeItem[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
commonCodeService.getByGroup(groupCode)
|
||||
.then((res) => {
|
||||
if (res.success && res.data) {
|
||||
setCodes(res.data.map((c: any) => ({
|
||||
codeValue: c.codeValue,
|
||||
codeName: c.codeName,
|
||||
sortOrder: c.sortOrder,
|
||||
})));
|
||||
}
|
||||
})
|
||||
.catch(() => {})
|
||||
.finally(() => setLoading(false));
|
||||
}, [groupCode]);
|
||||
|
||||
return { codes, loading };
|
||||
}
|
||||
Reference in New Issue
Block a user