полное имя вместо email
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import * as React from 'react';
|
||||
import { Employee } from '../models';
|
||||
import { ApiClientError } from '../services/httpClient';
|
||||
import { PortalDictionaryClient } from '../services/portalDictionary';
|
||||
|
||||
export interface PortalEmployees {
|
||||
items: Employee[];
|
||||
isLoading: boolean;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Справочник сотрудников api.tnsu.kz — грузим один раз на экран, чтобы искать
|
||||
* исполнителя/инициатора по ФИО или email на клиенте, без запроса на каждый символ.
|
||||
*/
|
||||
export function usePortalEmployees(dictionary?: PortalDictionaryClient): PortalEmployees {
|
||||
const [items, setItems] = React.useState<Employee[]>([]);
|
||||
const [isLoading, setIsLoading] = React.useState(true);
|
||||
const [error, setError] = React.useState<string | undefined>();
|
||||
|
||||
React.useEffect(() => {
|
||||
// Клиент появляется асинхронно: SPFx сначала выдаёт AAD-токен для api.tnsu.kz.
|
||||
if (!dictionary) return;
|
||||
|
||||
setIsLoading(true);
|
||||
setError(undefined);
|
||||
dictionary.employees()
|
||||
.then(setItems)
|
||||
.catch((e: ApiClientError) => setError(e.message))
|
||||
.finally(() => setIsLoading(false));
|
||||
}, [dictionary]);
|
||||
|
||||
return { items, isLoading, error };
|
||||
}
|
||||
Reference in New Issue
Block a user