warehouse locations
This commit is contained in:
@ -57,12 +57,14 @@ const ViewLocationPage: React.FC<ViewLocationPageProps> = ({ location }) => {
|
||||
{location.name}
|
||||
</button>
|
||||
{/* Backup Location Tab */}
|
||||
<button
|
||||
className={`tab flex-1 text-lg py-2 px-4 ${activeTab === 'backupLocation' ? 'border-b-4 border-blue-500 text-blue-600 font-semibold' : 'text-gray-600 hover:text-blue-500'}`}
|
||||
onClick={() => handleTabChange('backupLocation')}
|
||||
>
|
||||
При лошо време: <strong>{location.backupLocationName}</strong>
|
||||
</button>
|
||||
{location.backupLocationId !== null && (
|
||||
<button
|
||||
className={`tab flex-1 text-lg py-2 px-4 ${activeTab === 'backupLocation' ? 'border-b-4 border-blue-500 text-blue-600 font-semibold' : 'text-gray-600 hover:text-blue-500'}`}
|
||||
onClick={() => handleTabChange('backupLocation')}
|
||||
>
|
||||
При лошо време: <strong>{location.backupLocationName}</strong>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Carousel */}
|
||||
@ -98,6 +100,8 @@ const ViewLocationPage: React.FC<ViewLocationPageProps> = ({ location }) => {
|
||||
);
|
||||
};
|
||||
|
||||
const common = require("../../../src/helpers/common");
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
const axios = await axiosServer(context);
|
||||
|
||||
@ -126,17 +130,19 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
const { data: location } = await axios.get(
|
||||
`${process.env.NEXT_PUBLIC_PUBLIC_URL}/api/data/locations/${context.params.id}`
|
||||
);
|
||||
const prismaClient = common.getPrismaClient();
|
||||
const location = await getLocation(prismaClient, context);
|
||||
location.content = replacePlaceholders(location.content);
|
||||
|
||||
if (location.backupLocationId !== null) {
|
||||
const { data: backupLocation } = await axios.get(
|
||||
process.env.NEXT_PUBLIC_PUBLIC_URL + "/api/data/locations/" + location.backupLocationId
|
||||
);
|
||||
// const { data: backupLocation } = await axios.get(
|
||||
// process.env.NEXT_PUBLIC_PUBLIC_URL + "/api/data/locations/" + location.backupLocationId
|
||||
// );
|
||||
const backupLocation = await prismaClient.location.findFirst({
|
||||
where: {
|
||||
id: location.backupLocationId,
|
||||
},
|
||||
});
|
||||
location.backupLocationName = backupLocation.name;
|
||||
location.backupLocationContent = backupLocation ? replacePlaceholders(backupLocation.content) : "";
|
||||
location.backupLocationImages = backupLocation ? [backupLocation.picture1, backupLocation.picture2, backupLocation.picture3].filter(Boolean) : [];
|
||||
@ -151,4 +157,30 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
};
|
||||
};
|
||||
|
||||
async function getLocation(prismaClient, context) {
|
||||
// Try to parse the ID as a number
|
||||
const numericId = parseInt(context.params.id);
|
||||
let location;
|
||||
|
||||
// If it's a valid number, search by ID
|
||||
if (!isNaN(numericId)) {
|
||||
location = await prismaClient.location.findFirst({
|
||||
where: {
|
||||
id: numericId
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// If no location found by ID or if ID is not numeric, search by name
|
||||
if (!location) {
|
||||
location = await prismaClient.location.findFirst({
|
||||
where: {
|
||||
name: context.params.id
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
export default ViewLocationPage;
|
||||
|
Reference in New Issue
Block a user