Feature/5 pilots edit (#40)

* enabling pilot edit

* enabling pilot edit
This commit was merged in pull request #40.
This commit is contained in:
2025-02-03 02:55:09 +00:00
committed by GitHub
parent c71af4a793
commit fd28bbfd20
3 changed files with 18 additions and 10 deletions

View File

@@ -84,7 +84,7 @@ const LogForm: React.FC<ILogFormProps> = ({
} }
}); });
} else { } else {
await httpClient.put(`api/logs/${entryId}`, data, { await httpClient.put(`api/logs/log/${entryId}`, data, {
headers: { headers: {
Authorization: accessToken Authorization: accessToken
} }

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: {