Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

front: add switch for paced train #10629

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions front/public/locales/en/operationalStudies/scenario.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"modifyScenario": "Modify scenario",
"moreDetails": "more details",
"noElectricalProfileSet": "No electrical profile",
"pacedTrain": {
"pacedTrain": "Paced train"
},
"scenarioCancel": "Cancel",
"scenarioCreateButton": "Create a scenario",
"scenarioCreationTitle": "Create a scenario",
Expand Down
3 changes: 3 additions & 0 deletions front/public/locales/fr/operationalStudies/scenario.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"modifyScenario": "Modifier le scénario",
"moreDetails": "plus de détails",
"noElectricalProfileSet": "Pas de profil électrique",
"pacedTrain": {
"pacedTrain": "Mission"
},
"scenarioCancel": "Annuler",
"scenarioCreateButton": "Créer le scénario",
"scenarioCreationTitle": "Créer un scénario",
Expand Down
29 changes: 27 additions & 2 deletions front/src/common/UserSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@ import { useSelector } from 'react-redux';
import InputSNCF from 'common/BootstrapSNCF/InputSNCF';
import { ModalBodySNCF, ModalHeaderSNCF } from 'common/BootstrapSNCF/ModalSNCF';
import { updateUserPreferences } from 'reducers/user';
import { getUserPreferences } from 'reducers/user/userSelectors';
import { getIsSuperUser, getUserPreferences } from 'reducers/user/userSelectors';
import { useAppDispatch } from 'store';
import { useDebounce } from 'utils/helpers';

import SwitchSNCF from './BootstrapSNCF/SwitchSNCF/SwitchSNCF';

const UserSettings = () => {
const userPreferences = useSelector(getUserPreferences);
const [safeWordText, setSafeWordText] = useState(userPreferences.safeWord);
const dispatch = useAppDispatch();
const isSuperUser = useSelector(getIsSuperUser);

const debouncedSafeWord = useDebounce(safeWordText, 500);

useEffect(() => {
dispatch(updateUserPreferences({ ...userPreferences, safeWord: debouncedSafeWord }));
}, [debouncedSafeWord]);

const { t } = useTranslation(['home/navbar']);
const { t } = useTranslation(['home/navbar', 'operationalStudies/scenario']);
return (
<>
<ModalHeaderSNCF withCloseButton>
Expand Down Expand Up @@ -55,6 +58,28 @@ const UserSettings = () => {
<small id="safeWordHelpBlock" className="form-text text-muted">
{t('safeWordHelp')}
</small>
{
// TODO PACEDTRAIN: Remove switch after development pacedTrain feature
isSuperUser && (
<div className="d-flex align-items-center mt-2">
<SwitchSNCF
id="paced-train-switch"
type="switch"
name={t('operationalStudies/scenario:pacedTrain.pacedTrain')}
checked={userPreferences.showPacedTrains}
onChange={() =>
dispatch(
updateUserPreferences({
...userPreferences,
showPacedTrains: !userPreferences.showPacedTrains,
})
)
}
/>
<div className="ml-2">{t('operationalStudies/scenario:pacedTrain.pacedTrain')}</div>
</div>
)
}
</ModalBodySNCF>
</>
);
Expand Down
12 changes: 9 additions & 3 deletions front/src/reducers/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export interface UserState {
isLogged: boolean;
loginError?: ApiError;
username: string;
userPreferences: { safeWord: string };
// TODO PACEDTRAIN: Remove pacedTrain after development pacedTrain feature
userPreferences: { safeWord: string; showPacedTrains?: boolean };
userRoles: BuiltinRole[];
account: Record<string, string>;
}
Expand All @@ -16,7 +17,8 @@ export const userInitialState: UserState = {
isLogged: false,
loginError: undefined,
username: '',
userPreferences: { safeWord: '' },
// TODO PACEDTRAIN: Remove pacedTrain after development pacedTrain feature
userPreferences: { safeWord: '', showPacedTrains: false },
userRoles: [],
account: {},
};
Expand Down Expand Up @@ -45,7 +47,11 @@ export const userSlice = createSlice({
setUserRoles(state, action: PayloadAction<BuiltinRole[] | undefined>) {
state.userRoles = action.payload || [];
},
updateUserPreferences(state, action: PayloadAction<{ safeWord: string }>) {
updateUserPreferences(
Uriel-Sautron marked this conversation as resolved.
Show resolved Hide resolved
state,
// TODO PACEDTRAIN: Remove pacedTrain after development pacedTrain feature
action: PayloadAction<{ safeWord: string; showPacedTrains?: boolean }>
) {
state.userPreferences = action.payload;
},
},
Expand Down
3 changes: 3 additions & 0 deletions front/src/reducers/user/userSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export const getUsername = makeUserSelector('username');
export const getUserRoles = makeUserSelector('userRoles');
export const getIsSuperUser = (state: RootState) => getUserRoles(state).includes('Superuser');

// TODO PACEDTRAIN: Remove pacedTrain after development pacedTrain feature
export const getShowPacedTrains = makeUserPreferencesSelector('showPacedTrains');

const makeUserHasAllRequiredRolesSelector =
(requiredRoles: BuiltinRole[]) => (state: RootState) => {
const userRoles = getUserRoles(state);
Expand Down
Loading