add pilot
This commit is contained in:
@@ -28,7 +28,7 @@
|
|||||||
"@nestjs/core": "^10.0.0",
|
"@nestjs/core": "^10.0.0",
|
||||||
"@nestjs/passport": "^10.0.3",
|
"@nestjs/passport": "^10.0.3",
|
||||||
"@nestjs/platform-express": "^10.0.0",
|
"@nestjs/platform-express": "^10.0.0",
|
||||||
"@noahspan/noahspan-modules": "^0.3.4",
|
"@noahspan/noahspan-modules": "^0.3.5",
|
||||||
"@schematics/angular": "^17.3.7",
|
"@schematics/angular": "^17.3.7",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"reflect-metadata": "0.1.13",
|
"reflect-metadata": "0.1.13",
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export class AppController {
|
|||||||
@Query() query: any
|
@Query() query: any
|
||||||
): Promise<{ key: string; enabled: boolean }[]> {
|
): Promise<{ key: string; enabled: boolean }[]> {
|
||||||
try {
|
try {
|
||||||
|
console.log(query);
|
||||||
const featureFlagKeys: string[] =
|
const featureFlagKeys: string[] =
|
||||||
query.keys && query.keys.toString().includes(';')
|
query.keys && query.keys.toString().includes(';')
|
||||||
? query.keys.split(';')
|
? query.keys.split(';')
|
||||||
@@ -46,7 +47,8 @@ export class AppController {
|
|||||||
async getUserProfile(@Headers() headers: any) {
|
async getUserProfile(@Headers() headers: any) {
|
||||||
try {
|
try {
|
||||||
const graphToken: string = await this.msGraphService.getMsGraphAuth(
|
const graphToken: string = await this.msGraphService.getMsGraphAuth(
|
||||||
headers.authorization.replace('Bearer ', '')
|
headers.authorization.replace('Bearer ', ''),
|
||||||
|
['user.read']
|
||||||
);
|
);
|
||||||
const client: MsGraphClient =
|
const client: MsGraphClient =
|
||||||
await this.msGraphService.getMsGraphClientDelegated(graphToken);
|
await this.msGraphService.getMsGraphClientDelegated(graphToken);
|
||||||
@@ -64,17 +66,10 @@ export class AppController {
|
|||||||
@Query('search') search: any
|
@Query('search') search: any
|
||||||
): Promise<Person[]> {
|
): Promise<Person[]> {
|
||||||
try {
|
try {
|
||||||
const graphToken: string = await this.msGraphService.getMsGraphAuth(
|
const personSearchResults: Person[] =
|
||||||
headers.authorization.replace('Bearer ', '')
|
await getPersonSearshResults(search);
|
||||||
);
|
|
||||||
const client: MsGraphClient =
|
|
||||||
await this.msGraphService.getMsGraphClientDelegated(graphToken);
|
|
||||||
const results: any = await client
|
|
||||||
.api(`me/people/?$search=${search}`)
|
|
||||||
.get();
|
|
||||||
const personResults: Person[] = results.values ? results.values : [];
|
|
||||||
|
|
||||||
return personResults;
|
return personSearchResults;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ const App: React.FC<unknown> = () => {
|
|||||||
const response: AxiosResponse = await httpClient.get(
|
const response: AxiosResponse = await httpClient.get(
|
||||||
`api/featureFlags?keys=${featureFlagKeys}&label=${import.meta.env.MODE}`
|
`api/featureFlags?keys=${featureFlagKeys}&label=${import.meta.env.MODE}`
|
||||||
);
|
);
|
||||||
|
console.log(response.data);
|
||||||
const featureFlags: { key: string; enabled: boolean }[] = response.data;
|
const featureFlags: { key: string; enabled: boolean }[] = response.data;
|
||||||
|
|
||||||
if (featureFlags.length > 0) {
|
if (featureFlags.length > 0) {
|
||||||
|
|||||||
@@ -14,18 +14,18 @@ import {
|
|||||||
} from '@noahspan/noahspan-components';
|
} from '@noahspan/noahspan-components';
|
||||||
import PilotFormCertificates from '../pilotFormCertificates/PilotFormCertificates';
|
import PilotFormCertificates from '../pilotFormCertificates/PilotFormCertificates';
|
||||||
import PilotFormEndorsements from '../pilotFormEndorsements/PilotFormEndorsements';
|
import PilotFormEndorsements from '../pilotFormEndorsements/PilotFormEndorsements';
|
||||||
import { Person } from '@microsoft/microsoft-graph-types';
|
// import { Person } from '@microsoft/microsoft-graph-types';
|
||||||
import { AxiosInstance, AxiosResponse } from 'axios';
|
import { AxiosInstance, AxiosResponse } from 'axios';
|
||||||
import { useHttpClient } from '../../hooks/httpClient/UseHttpClient';
|
import { useHttpClient } from '../../hooks/httpClient/UseHttpClient';
|
||||||
import { useAccount } from '@azure/msal-react';
|
import { useAccessToken } from '../../hooks/accessToken/UseAcessToken';
|
||||||
|
|
||||||
const PilotForm: React.FC<unknown> = () => {
|
const PilotForm: React.FC<unknown> = () => {
|
||||||
const httpClient: AxiosInstance = useHttpClient();
|
const httpClient: AxiosInstance = useHttpClient();
|
||||||
const accountInfo = useAccount();
|
|
||||||
const [open, setOpen] = useState<number>(0);
|
const [open, setOpen] = useState<number>(0);
|
||||||
const [peoplePickerResults, setPeoplePickerResults] = useState<Person[]>([]);
|
const [peoplePickerResults, setPeoplePickerResults] = useState<any[]>([]);
|
||||||
const [isPeoplePickerLoading, setIsPeoplePickerLoading] =
|
const [isPeoplePickerLoading, setIsPeoplePickerLoading] =
|
||||||
useState<boolean>(false);
|
useState<boolean>(false);
|
||||||
|
const { getAccessToken } = useAccessToken();
|
||||||
const handleOpen = (value: number) => {
|
const handleOpen = (value: number) => {
|
||||||
setOpen(open === value ? 0 : value);
|
setOpen(open === value ? 0 : value);
|
||||||
};
|
};
|
||||||
@@ -39,21 +39,32 @@ const PilotForm: React.FC<unknown> = () => {
|
|||||||
const handlePeoplePickerOnChange = async (
|
const handlePeoplePickerOnChange = async (
|
||||||
event: React.ChangeEvent<HTMLInputElement>
|
event: React.ChangeEvent<HTMLInputElement>
|
||||||
) => {
|
) => {
|
||||||
|
setIsPeoplePickerLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
const searchString: string = event.target.value;
|
const searchString: string = event.target.value;
|
||||||
|
const accessToken: string = await getAccessToken();
|
||||||
const response: AxiosResponse = await httpClient.get(
|
const response: AxiosResponse = await httpClient.get(
|
||||||
`api/personSearch?search=${searchString}`,
|
`api/personSearch?search=${searchString}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accountInfo?.idToken}`
|
Authorization: accessToken
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
console.log(response);
|
||||||
|
setPeoplePickerResults(response.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
} finally {
|
||||||
|
setIsPeoplePickerLoading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormProvider {...methods}>
|
<FormProvider {...methods}>
|
||||||
<form className="m-10" onSubmit={handleSubmit(onSubmit)}>
|
<form className="m-10" onSubmit={handleSubmit(onSubmit)}>
|
||||||
{/* <Accordion
|
<Accordion
|
||||||
open={open === 1}
|
open={open === 1}
|
||||||
icon={open === 1 ? <ChevronDownIcon /> : <ChevronUpIcon />}
|
icon={open === 1 ? <ChevronDownIcon /> : <ChevronUpIcon />}
|
||||||
>
|
>
|
||||||
@@ -64,7 +75,7 @@ const PilotForm: React.FC<unknown> = () => {
|
|||||||
<Controller
|
<Controller
|
||||||
name="name"
|
name="name"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field }) => (
|
render={() => (
|
||||||
<PeoplePicker
|
<PeoplePicker
|
||||||
results={peoplePickerResults}
|
results={peoplePickerResults}
|
||||||
inputProps={{
|
inputProps={{
|
||||||
@@ -129,7 +140,7 @@ const PilotForm: React.FC<unknown> = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</AccordionBody>
|
</AccordionBody>
|
||||||
</Accordion> */}
|
</Accordion>
|
||||||
<Accordion
|
<Accordion
|
||||||
open={open === 2}
|
open={open === 2}
|
||||||
icon={open === 2 ? <ChevronDownIcon /> : <ChevronUpIcon />}
|
icon={open === 2 ? <ChevronDownIcon /> : <ChevronUpIcon />}
|
||||||
|
|||||||
32
app/src/hooks/accessToken/UseAcessToken.tsx
Normal file
32
app/src/hooks/accessToken/UseAcessToken.tsx
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import {
|
||||||
|
AuthenticationResult,
|
||||||
|
InteractionRequiredAuthError
|
||||||
|
} from '@azure/msal-browser';
|
||||||
|
import { useMsal } from '@azure/msal-react';
|
||||||
|
|
||||||
|
export const useAccessToken = () => {
|
||||||
|
const { accounts, instance } = useMsal();
|
||||||
|
const getAccessToken = async () => {
|
||||||
|
const tokenRequest = {
|
||||||
|
account: accounts[0],
|
||||||
|
scopes: [`api://${import.meta.env.VITE_CLIENT_ID}/user_impersonation`]
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response: AuthenticationResult =
|
||||||
|
await instance.acquireTokenSilent(tokenRequest);
|
||||||
|
console.log(response.accessToken);
|
||||||
|
return `Bearer ${response.accessToken}`;
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof InteractionRequiredAuthError) {
|
||||||
|
await instance.acquireTokenRedirect(tokenRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
getAccessToken
|
||||||
|
};
|
||||||
|
};
|
||||||
8
package-lock.json
generated
8
package-lock.json
generated
@@ -38,7 +38,7 @@
|
|||||||
"@nestjs/core": "^10.0.0",
|
"@nestjs/core": "^10.0.0",
|
||||||
"@nestjs/passport": "^10.0.3",
|
"@nestjs/passport": "^10.0.3",
|
||||||
"@nestjs/platform-express": "^10.0.0",
|
"@nestjs/platform-express": "^10.0.0",
|
||||||
"@noahspan/noahspan-modules": "^0.3.4",
|
"@noahspan/noahspan-modules": "^0.3.5",
|
||||||
"@schematics/angular": "^17.3.7",
|
"@schematics/angular": "^17.3.7",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"reflect-metadata": "0.1.13",
|
"reflect-metadata": "0.1.13",
|
||||||
@@ -3419,9 +3419,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@noahspan/noahspan-modules": {
|
"node_modules/@noahspan/noahspan-modules": {
|
||||||
"version": "0.3.4",
|
"version": "0.3.5",
|
||||||
"resolved": "https://registry.npmjs.org/@noahspan/noahspan-modules/-/noahspan-modules-0.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/@noahspan/noahspan-modules/-/noahspan-modules-0.3.5.tgz",
|
||||||
"integrity": "sha512-bmcMshrfODrZCo+zTw8Ojn9FzjhPz6yYepSgPTniF4i0XEeZDdgAZdNRbe2yRtC+RedLt6Hx+HGQfKMMcPkqNA==",
|
"integrity": "sha512-VUCEtJcFTcrVyROMDpP8a90LFez5VPzo//0pUdHlpV7KqIDPRPpp7z/RXkXoUBYM0g06kS2CD5t3ZtzyIewBNg==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@azure/app-configuration": "^1.6.0",
|
"@azure/app-configuration": "^1.6.0",
|
||||||
"@azure/identity": "^4.2.0",
|
"@azure/identity": "^4.2.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user