



//next.js page to show all locatons in the database with a link to the location page
import { Availability } from "@prisma/client";
import AvailabilityForm from "../../../components/availability/AvailabilityForm";
import Layout from "../../../components/layout";
import axiosServer from '../../../src/axiosServer';


export default function NewPage(item: Availability) {
  return (
    <Layout>
      <div className="h-5/6 grid place-items-center">
        <AvailabilityForm existingItems={[item]} publisherId={item.publisherId} />
      </div>
    </Layout>
  );
}

//------------------pages\cart\availabilities\edit\[id].tsx------------------

export const getServerSideProps = async (context) => {

  const axios = await axiosServer(context);
  context.res.setHeader("Cache-Control", "s-maxage=1, stale-while-revalidate");
  if (!context.query || !context.query.id) {
    return {
      props: {}
    };
  }
  const { data: item } = await axios.get(
    process.env.NEXT_PUBLIC_PUBLIC_URL + "/api/data/availabilities/" + context.params.id
  );

  return {
    props: {
      item: item,
    },
  };
};
