Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. export const InvoiceForm = ({isCreatingInvoice, setIsCreatingInvoice, invoiceID}) => {
  2. const [alert, setAlert] = useState(null);
  3.  
  4. const animation1 = 'animated slideInRight faster';
  5. const alertClasses = useAlertStyles();
  6.  
  7. function hideAlert(){
  8. setAlert(null);
  9. }
  10.  
  11. /* I need this to be called if my X button is clicked in the Parent component.
  12. However, there's no to get values as it is only accessible from within the child component.
  13. handleSubmit is already wired up w/ formik/formik-wizard
  14. */
  15. function resetData(values){
  16. let result = false;
  17.  
  18. if( !Array.isArray(values.lineItems.data) || values.lineItems.data.length > 0){
  19. values.lineItems.data = [];
  20. result = true;
  21. }
  22.  
  23. return result;
  24. }
  25.  
  26. const handleSubmit = useCallback(values => {
  27. (async () => {
  28. //attempt to POST Data here.
  29.  
  30. //ON SUCCESS reset table data and hide invoice creation component
  31. if(resetData(values)){
  32. setAlert('success')
  33. }
  34. else{
  35. setAlert('error');
  36. return { message: 'Something went wrong submitting. Please try again!', reason:'Error reseting table data'}
  37. }
  38. })();
  39. })
  40.  
  41. if(isCreatingInvoice){
  42. return(
  43. <div className={animation1}>
  44. <RevWizard
  45. steps={InvoiceFormSteps}
  46. handleSubmit={handleSubmit}
  47. iconText={`Invoice #${invoiceID}`}
  48. />
  49. </div>
  50. );
  51. }
  52. else{
  53. return ( null )
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement