Feature/5 pilots edit #40

Merged
noahspannbauer merged 2 commits from feature/5-pilots---edit into main 2025-02-02 21:55:09 -05:00
2 changed files with 17 additions and 9 deletions
Showing only changes of commit fd26f0851e - Show all commits

View File

@@ -99,6 +99,7 @@ const PilotForm: React.FC<IPilotFormProps> = ({
methods.reset(defaultValues); methods.reset(defaultValues);
onOpenClose(FormMode.CANCEL); onOpenClose(FormMode.CANCEL);
setSelectedPerson({ userPrincipalName: '', displayName: '' }); setSelectedPerson({ userPrincipalName: '', displayName: '' });
setIsDisabled(false)
}; };
const onSubmit = async (data: unknown) => { const onSubmit = async (data: unknown) => {
@@ -107,12 +108,21 @@ const PilotForm: React.FC<IPilotFormProps> = ({
const accessToken: string = await getAccessToken(); const accessToken: string = await getAccessToken();
await httpClient.post(`api/pilots`, data, { if (!pilotId) {
headers: { await httpClient.post(`api/pilots`, data, {
Authorization: accessToken headers: {
} Authorization: accessToken
}); }
});
} else {
await httpClient.put(`api/pilots/pilot/${pilotId}`, data, {
headers: {
Authorization: accessToken
}
})
}
methods.reset(defaultValues)
onOpenClose(FormMode.CANCEL); onOpenClose(FormMode.CANCEL);
} catch (error) { } catch (error) {
const axiosError = error as AxiosError; const axiosError = error as AxiosError;
@@ -139,17 +149,16 @@ const PilotForm: React.FC<IPilotFormProps> = ({
? { headers: { Authorization: await getAccessToken() } } ? { headers: { Authorization: await getAccessToken() } }
: {}; : {};
const response: AxiosResponse = await httpClient.get( const response: AxiosResponse = await httpClient.get(
`api/pilots/${pilotId}`, `api/pilots/pilot/${pilotId}`,
config config
); );
const pilot = response.data; const pilot = response.data;
console.log(pilot);
setSelectedPerson({ setSelectedPerson({
userPrincipalName: pilot.id, userPrincipalName: pilot.id,
displayName: pilot.name displayName: pilot.name
}); });
methods.reset(pilot); methods.reset(pilot);
console.log(methods.getValues());
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} finally { } finally {

View File

@@ -52,7 +52,6 @@ const SiteNav: React.FC<unknown> = () => {
instance.logoutRedirect(); instance.logoutRedirect();
}; };
const getUserProfile = async (accessToken: string): Promise<User> => { const getUserProfile = async (accessToken: string): Promise<User> => {
console.log(accessToken)
try { try {
const response: AxiosResponse = await httpClient.get(`api/userProfile`, { const response: AxiosResponse = await httpClient.get(`api/userProfile`, {
headers: { headers: {