fixing logbook non authenticated (#53)

This commit was merged in pull request #53.
This commit is contained in:
2025-02-24 18:55:49 +00:00
committed by GitHub
parent c765b06404
commit 07575302cc
4 changed files with 91 additions and 62 deletions

View File

@@ -20,6 +20,7 @@ import { Public } from '@noahspan/noahspan-modules';
export class LogController { export class LogController {
constructor(private readonly logService: LogService) {} constructor(private readonly logService: LogService) {}
@Public()
@Get(':partitionKey/:rowKey') @Get(':partitionKey/:rowKey')
async find( async find(
@Param('partitionKey') partitionKey: string, @Param('partitionKey') partitionKey: string,

View File

@@ -9,6 +9,7 @@ async function bootstrap() {
const httpService = new HttpService(); const httpService = new HttpService();
const app = await NestFactory.create(AppModule); const app = await NestFactory.create(AppModule);
app.enableCors();
app.setGlobalPrefix('api'); app.setGlobalPrefix('api');
app.useGlobalFilters(new HttpExceptionFilter()); app.useGlobalFilters(new HttpExceptionFilter());

View File

@@ -12,11 +12,13 @@ import {
TrashIcon TrashIcon
} from '@noahspan/noahspan-components'; } from '@noahspan/noahspan-components';
import { FormMode } from '../../enums/formMode'; import { FormMode } from '../../enums/formMode';
import { useIsAuthenticated } from '@azure/msal-react';
const ActionMenu = ({ id, onDelete, onOpenCloseForm }: IActionMenuProps) => { const ActionMenu = ({ id, onDelete, onOpenCloseForm }: IActionMenuProps) => {
const [anchorElAction, setAnchorElAction] = useState<null | HTMLElement>( const [anchorElAction, setAnchorElAction] = useState<null | HTMLElement>(
null null
); );
const isAuthenticated = useIsAuthenticated();
const onOpenActionMenu = (event: React.MouseEvent<HTMLElement>) => { const onOpenActionMenu = (event: React.MouseEvent<HTMLElement>) => {
setAnchorElAction(event.currentTarget); setAnchorElAction(event.currentTarget);
@@ -37,18 +39,22 @@ const ActionMenu = ({ id, onDelete, onOpenCloseForm }: IActionMenuProps) => {
open={Boolean(anchorElAction)} open={Boolean(anchorElAction)}
onClose={onCloseActionMenu} onClose={onCloseActionMenu}
> >
{isAuthenticated &&
<MenuItem onClick={() => onOpenCloseForm(FormMode.EDIT, id)}> <MenuItem onClick={() => onOpenCloseForm(FormMode.EDIT, id)}>
<ListItemIcon> <ListItemIcon>
<PenIcon size="lg" /> <PenIcon size="lg" />
</ListItemIcon> </ListItemIcon>
<ListItemText>Edit</ListItemText> <ListItemText>Edit</ListItemText>
</MenuItem> </MenuItem>
}
<MenuItem onClick={() => onOpenCloseForm(FormMode.VIEW, id)}> <MenuItem onClick={() => onOpenCloseForm(FormMode.VIEW, id)}>
<ListItemIcon> <ListItemIcon>
<EyeIcon size="lg" /> <EyeIcon size="lg" />
</ListItemIcon> </ListItemIcon>
<ListItemText>View</ListItemText> <ListItemText>View</ListItemText>
</MenuItem> </MenuItem>
{isAuthenticated &&
<>
<hr className="my-3" /> <hr className="my-3" />
<MenuItem onClick={() => onDelete(id)}> <MenuItem onClick={() => onDelete(id)}>
<ListItemIcon> <ListItemIcon>
@@ -56,6 +62,8 @@ const ActionMenu = ({ id, onDelete, onOpenCloseForm }: IActionMenuProps) => {
</ListItemIcon> </ListItemIcon>
<ListItemText>Delete</ListItemText> <ListItemText>Delete</ListItemText>
</MenuItem> </MenuItem>
</>
}
</Menu> </Menu>
</div> </div>
); );

View File

@@ -122,7 +122,7 @@ const LogForm: React.FC<ILogFormProps> = ({
config config
); );
const entry = response.data; const entry = response.data;
console.log(entry)
methods.reset(entry); methods.reset(entry);
} catch (error) { } catch (error) {
const axiosError = error as AxiosError; const axiosError = error as AxiosError;
@@ -186,6 +186,8 @@ const LogForm: React.FC<ILogFormProps> = ({
</Alert> </Alert>
</Grid> </Grid>
)} )}
{!FormMode.VIEW &&
<>
<Grid alignItems="center" display="flex" size={4}> <Grid alignItems="center" display="flex" size={4}>
<Typography variant="body1">Pilot *</Typography> <Typography variant="body1">Pilot *</Typography>
</Grid> </Grid>
@@ -195,7 +197,7 @@ const LogForm: React.FC<ILogFormProps> = ({
control={methods.control} control={methods.control}
render={({ field: { onChange, value } }) => { render={({ field: { onChange, value } }) => {
useEffect(() => { useEffect(() => {
if (value && mode !== FormMode.ADD) { if (value) {
const pilot = pilots?.find((pilot) => pilot.id === value); const pilot = pilots?.find((pilot) => pilot.id === value);
dispatch({ dispatch({
@@ -230,18 +232,35 @@ const LogForm: React.FC<ILogFormProps> = ({
value={value} value={value}
/> />
)} )}
{mode !== FormMode.ADD && (
<TextField
disabled={true}
fullWidth
value={state.selectedEntryPilotName}
/>
)}
</> </>
); );
}} }}
/> />
</Grid> </Grid>
</>
}
{FormMode.VIEW &&
<>
<Grid alignItems="center" display="flex" size={4}>
<Typography variant="body1">Pilot *</Typography>
</Grid>
<Grid size={8}>
<Controller
name="pilotName"
control={methods.control}
render={({ field: { value } }) => {
return (
<TextField
disabled={true}
fullWidth
value={value}
/>
)
}}
/>
</Grid>
</>
}
<Grid alignItems="center" display="flex" size={4}> <Grid alignItems="center" display="flex" size={4}>
<Typography variant="body1">Date *</Typography> <Typography variant="body1">Date *</Typography>
</Grid> </Grid>