import React from 'react';
import PropTypes from 'prop-types';
import CreateConnector from './CreateConnector';
import QuestionForm from './Form';
import { formValuesToRequest } from './transforms';
import { questionInitialValues, createHandleSubmit } from './CreateDialog';
import NextLink from 'next/link';
import FAButton from '../FAButton';
import ArrowBackIcon from '@material-ui/icons/ArrowBack';

const QuestionCreateForm = () => (
  <React.Fragment>
    <NextLink href={`/admin/questoes`}>
      <FAButton aria-label="Voltar pra lista de questões">
        <ArrowBackIcon />
      </FAButton>
    </NextLink>
    <CreateConnector>
      {({ createQuestion }) => (
        <QuestionForm
          initialValues={questionInitialValues}
          onSubmit={createHandleSubmit(createQuestion)}
        />
      )}
    </CreateConnector>
  </React.Fragment>
);

export default QuestionCreateForm;

@@ -272,42 +272,8 @@
 g';%0A
-import NextLink from 'next/link';%0A
 impo
@@ -366,224 +366,316 @@
 k';%0A
-%0Aconst QuestionCreateForm =
+import Router from 'next/router';%0A%0Aconst createBackToListHandler = isDirty =%3E
  () =%3E 
-(%0A  %3CReact.Fragment%3E%0A    %3CNextLink href=%7B%60/admin/questoes%60%7D%3E%0A      %3CFAButton aria-label=%22Voltar pra lista de quest%C3%B5es%22%3E%0A        %3CArrowBackIcon /%3E%0A      %3C/FAButton%3E%0A    %3C/NextLink%3E%0A  
+%7B%0A  console.log('isDirty: ');%0A  console.log(isDirty);%0A  if (isDirty) %7B%0A    console.log('Your form has changed! You can not go back.');%0A    return;%0A  %7D%0A  Router.push('/admin/questoes');%0A%7D;%0A%0Aconst QuestionCreateForm = () =%3E (%0A
   %3CC
@@ -690,18 +690,16 @@
 nector%3E%0A
-  
     %7B(%7B 
@@ -721,18 +721,16 @@
 %7D) =%3E (%0A
-  
       %3CQ
@@ -749,18 +749,16 @@
         
-  
 initialV
@@ -787,18 +787,16 @@
 Values%7D%0A
-  
         
@@ -851,63 +851,382 @@
     
-  /%3E%0A      )%7D%0A    %3C/CreateConnector%3E%0A  %3C/React.Fragment
+%3E%0A        %7B(%7B form, isDirty %7D) =%3E (%0A          %3CReact.Fragment%3E%0A            %3CFAButton%0A              onClick=%7BcreateBackToListHandler(isDirty)%7D%0A              aria-label=%22Voltar pra lista de quest%C3%B5es%22%0A            %3E%0A              %3CArrowBackIcon /%3E%0A            %3C/FAButton%3E%0A            %7Bform%7D%0A          %3C/React.Fragment%3E%0A        )%7D%0A      %3C/QuestionForm%3E%0A    )%7D%0A  %3C/CreateConnector
 %3E%0A);

Check if form is dirty before going back to question list