import {
  CLOSE_MODAL,
  OPEN_MODAL,
} from "../../../../../lib/redux/slices/appSlice";
import { ProvinceManageGuildsSubmitRegisterCode } from "../../province-manage-guilds-submit-register-code/ProvinceManageGuildsSubmitRegisterCode";

export const handleSubmitSuccess = (
  dispatch,
  openNotif,
  updateTable,
  values,
  responseData
) => {
  updateTable();
  openNotif({
    vertical: "top",
    horizontal: "center",
    msg: "عملیات با موفقیت انجام شد.",
    severity: "success",
  });
  dispatch(CLOSE_MODAL());

  if (values.verify_mobile && responseData) {
    dispatch(
      OPEN_MODAL({
        title: "ثبت کد احراز",
        content: (
          <ProvinceManageGuildsSubmitRegisterCode
            item={responseData}
            updateTable={updateTable}
          />
        ),
      })
    );
  }
};

export const handleSubmitError = (openNotif, error) => {
  openNotif({
    vertical: "top",
    horizontal: "center",
    msg: error,
    severity: "error",
  });
};
