enabling pilot edit

This commit is contained in:
2025-02-02 20:51:05 -06:00
parent c71af4a793
commit fd26f0851e
2 changed files with 17 additions and 9 deletions

View File

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

View File

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