fixing logbook non authenticated #53

Merged
noahspannbauer merged 1 commits from bug/45-action-menu-edit-and-delete-visible-to-non-auth-user into main 2025-02-24 13:55:50 -05:00
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,25 +39,31 @@ const ActionMenu = ({ id, onDelete, onOpenCloseForm }: IActionMenuProps) => {
open={Boolean(anchorElAction)} open={Boolean(anchorElAction)}
onClose={onCloseActionMenu} onClose={onCloseActionMenu}
> >
<MenuItem onClick={() => onOpenCloseForm(FormMode.EDIT, id)}> {isAuthenticated &&
<ListItemIcon> <MenuItem onClick={() => onOpenCloseForm(FormMode.EDIT, id)}>
<PenIcon size="lg" /> <ListItemIcon>
</ListItemIcon> <PenIcon size="lg" />
<ListItemText>Edit</ListItemText> </ListItemIcon>
</MenuItem> <ListItemText>Edit</ListItemText>
</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>
<hr className="my-3" /> {isAuthenticated &&
<MenuItem onClick={() => onDelete(id)}> <>
<ListItemIcon> <hr className="my-3" />
<TrashIcon size="lg" /> <MenuItem onClick={() => onDelete(id)}>
</ListItemIcon> <ListItemIcon>
<ListItemText>Delete</ListItemText> <TrashIcon size="lg" />
</MenuItem> </ListItemIcon>
<ListItemText>Delete</ListItemText>
</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,62 +186,81 @@ const LogForm: React.FC<ILogFormProps> = ({
</Alert> </Alert>
</Grid> </Grid>
)} )}
<Grid alignItems="center" display="flex" size={4}> {!FormMode.VIEW &&
<Typography variant="body1">Pilot *</Typography> <>
</Grid> <Grid alignItems="center" display="flex" size={4}>
<Grid size={8}> <Typography variant="body1">Pilot *</Typography>
<Controller </Grid>
name="pilotId" <Grid size={8}>
control={methods.control} <Controller
render={({ field: { onChange, value } }) => { name="pilotId"
useEffect(() => { control={methods.control}
if (value && mode !== FormMode.ADD) { render={({ field: { onChange, value } }) => {
const pilot = pilots?.find((pilot) => pilot.id === value); useEffect(() => {
if (value) {
const pilot = pilots?.find((pilot) => pilot.id === value);
dispatch({ dispatch({
type: 'SET_SELECTED_ENTRY_PILOT_NAME', type: 'SET_SELECTED_ENTRY_PILOT_NAME',
payload: pilot.name payload: pilot.name
}); });
} }
}, [value]); }, [value]);
return ( return (
<> <>
{mode === FormMode.ADD && ( {mode === FormMode.ADD && (
<Select <Select
disabled={state.isDisabled} disabled={state.isDisabled}
fullWidth fullWidth
onChange={(event) => { onChange={(event) => {
const pilot = pilots?.find( const pilot = pilots?.find(
(pilot) => (pilot.id = event.target.value) (pilot) => (pilot.id = event.target.value)
); );
if (pilot) { if (pilot) {
methods.setValue('pilotName', pilot.name); methods.setValue('pilotName', pilot.name);
} }
methods.setValue('pilotId', event.target.value); methods.setValue('pilotId', event.target.value);
}} }}
options={ options={
state.pilotOptions && state.pilotOptions.length > 0 state.pilotOptions && state.pilotOptions.length > 0
? state.pilotOptions ? state.pilotOptions
: [] : []
} }
value={value} value={value}
/> />
)} )}
{mode !== FormMode.ADD && ( </>
);
}}
/>
</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 <TextField
disabled={true} disabled={true}
fullWidth fullWidth
value={state.selectedEntryPilotName} value={value}
/> />
)} )
</> }}
); />
}} </Grid>
/> </>
</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>