fix: edit title bug

pull/100/head
Pierre-Louis Guhur 10 months ago
parent efe6693878
commit 9e3b654367

@ -232,19 +232,13 @@ const HeaderRubbonMobile = () => {
)
}
const ManageElection = ({context, token}) => {
const ManageElection = ({token}) => {
const {t} = useTranslation();
const [election, dispatch] = useElection();
const [_, dispatchApp] = useAppContext();
const router = useRouter();
const [waiting, setWaiting] = useState(false);
useEffect(() => {
if (context) {
dispatch({type: ElectionTypes.RESET, value: context});
}
}, [context]);
const handleSubmit = async () => {
if (!checkName(election)) {
dispatchApp({
@ -400,6 +394,7 @@ const ManageElection = ({context, token}) => {
const numGrades = election.grades.filter(
(g) => g.active && g.name != ''
).length;
console.log(election.name, numCandidates, numGrades)
const disabled =
!election.name ||
election.name == '' ||
@ -422,15 +417,12 @@ const ManageElection = ({context, token}) => {
fluid="xl"
className="my-5 flex-column d-flex justify-content-center"
>
<Container className="px-0 d-md-none mb-5">
<h4>{t('admin.confirm-title')}</h4>
</Container>
<Row>
<Col className={isClosed(election) ? 'col-12' : 'col-lg-3 col-12'}>
<Container className="py-4 d-none d-md-block">
<h4>{t('common.the-vote')}</h4>
</Container>
<TitleField defaultName={context.name} />
<TitleField defaultName={election.name} />
<CandidatesConfirmField />
</Col>
{!isClosed(election) && (
@ -473,9 +465,9 @@ const ManageElectionProviding = ({err, context, token}) => {
return <ErrorMessage>{t('admin.error')}</ErrorMessage>;
}
return (
<ElectionProvider>
<ElectionProvider initialValue={context}>
<Blur />
<ManageElection context={context} token={token} />
<ManageElection token={token} />
</ElectionProvider>
);
};

@ -112,11 +112,16 @@ const ElectionContext = createContext<[ElectionContextInterface, DispatchType]>(
[defaultElection, () => {}]
);
export function ElectionProvider({children}) {
type ElectionProviderType = {
children: React.ReactNode;
initialValue?: ElectionContextInterface;
};
export const ElectionProvider = ({children, initialValue}: ElectionProviderType) => {
/**
* Provide the election and the dispatch to all children components
*/
const [election, dispatch] = useReducer(electionReducer, defaultElection);
const [election, dispatch] = useReducer(electionReducer, initialValue || defaultElection);
// At the initialization, set the name using GET param
const router = useRouter();

Loading…
Cancel
Save