-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
270 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
import { RevalidateFeaturedListings } from "./Sections/RevalidateFeaturedListings"; | ||
import { RevalidateAllFeaturedListings } from "./Sections/RevalidateAllFeaturedListings"; | ||
import { RevalidateAllPostedListings } from "./Sections/RevalidateAllPostedListings"; | ||
import { RevalidateCitiesAndStates } from "./Sections/RevalidateCitiesAndStates"; | ||
import { RevalidateFeaturedListingsByCountry } from "./Sections/RevalidateFeaturedListingsByCountry"; | ||
import { RevalidateFeatures } from "./Sections/RevalidateFeatures"; | ||
import { RevalidatePostedListings } from "./Sections/RevalidatePostedListings"; | ||
import { RevalidatePostedListingsByCountry } from "./Sections/RevalidatePostedListingsByCountry"; | ||
import { RevalidateRelatedListings } from "./Sections/RevalidateRelatedListings"; | ||
import { RevalidateUserNotifications } from "./Sections/RevalidateUserNotifications"; | ||
import { RevalidateUserProfileDetails } from "./Sections/RevalidateUserProfileDetails"; | ||
import { RevalidateVehicleBrands } from "./Sections/RevalidateVehicleBrands"; | ||
|
||
export const ManageCache = () => { | ||
return ( | ||
<div className="my-4 grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3"> | ||
<RevalidateFeatures /> | ||
<RevalidateVehicleBrands /> | ||
<RevalidatePostedListings /> | ||
<RevalidateFeaturedListings /> | ||
<RevalidateCitiesAndStates /> | ||
<RevalidateAllPostedListings /> | ||
<RevalidatePostedListingsByCountry /> | ||
<RevalidateAllFeaturedListings /> | ||
<RevalidateFeaturedListingsByCountry /> | ||
<RevalidateRelatedListings /> | ||
<RevalidateUserNotifications /> | ||
<RevalidateUserProfileDetails /> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/components/ManageCache/Sections/RevalidateAllPostedListings.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use client"; | ||
|
||
import { useMutation } from "@tanstack/react-query"; | ||
import { toast } from "react-hot-toast"; | ||
import { revalidateAllPosedListingsAction } from "@/actions/cacheActions"; | ||
|
||
export const RevalidateAllPostedListings = () => { | ||
const { mutate, isLoading } = useMutation(async () => revalidateAllPosedListingsAction(), { | ||
onSuccess: () => toast.success(`Successfully revalidated all posted listings`), | ||
onError: () => toast.error(`Failed to revalidate all posted listings`), | ||
}); | ||
|
||
return ( | ||
<button className="btn btn-outline" disabled={isLoading} onClick={() => mutate()}> | ||
Revalidate all posted listings | ||
</button> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/components/ManageCache/Sections/RevalidateFeaturedListingsByCountry.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"use client"; | ||
|
||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { useState } from "react"; | ||
import { useForm } from "react-hook-form"; | ||
import { toast } from "react-hot-toast"; | ||
import { z } from "zod"; | ||
import { revalidateFeaturedListingsByCountryAction } from "@/actions/cacheActions"; | ||
import { Modal, ModalFooter } from "@/components/Common"; | ||
import { AutocompleteController } from "@/components/FormElements/AutoComplete"; | ||
import { COUNTRIES } from "@/utils/countries"; | ||
import { LabelValue } from "@/utils/types"; | ||
|
||
const RevalidateFeaturedListingsByCountrySchema = z.object({ country: z.string() }); | ||
|
||
type RevalidateFeaturedListingsByCountryReq = z.infer<typeof RevalidateFeaturedListingsByCountrySchema>; | ||
|
||
export const RevalidateFeaturedListingsByCountry = () => { | ||
const [modalVisible, setModalVisible] = useState(false); | ||
|
||
const { handleSubmit, control } = useForm<RevalidateFeaturedListingsByCountryReq>({ | ||
resolver: zodResolver(RevalidateFeaturedListingsByCountrySchema), | ||
mode: "all", | ||
}); | ||
|
||
const { mutate, isLoading } = useMutation( | ||
(req: RevalidateFeaturedListingsByCountryReq) => { | ||
const countryCode = Object.keys(COUNTRIES).find((item) => COUNTRIES[item]?.[0] === req.country); | ||
return revalidateFeaturedListingsByCountryAction(countryCode!); | ||
}, | ||
{ | ||
onMutate: () => setModalVisible(false), | ||
onSuccess: () => toast.success(`Successfully revalidated featured listings`), | ||
onError: () => toast.error(`Failed to revalidate featured listings`), | ||
}, | ||
); | ||
|
||
const countryList: LabelValue[] = Object.keys(COUNTRIES).map((key) => ({ | ||
label: COUNTRIES[key]?.[0]!, | ||
value: COUNTRIES[key]?.[0]!, | ||
})); | ||
|
||
return ( | ||
<> | ||
<button className="btn btn-outline" disabled={isLoading} onClick={() => setModalVisible(true)}> | ||
Revalidate featured listings by country | ||
</button> | ||
<Modal onVisibleChange={setModalVisible} title="Revalidate featured listings by country" visible={!!modalVisible}> | ||
<form className="grid gap-1"> | ||
<AutocompleteController | ||
control={control} | ||
fieldName="country" | ||
label="Country" | ||
options={countryList} | ||
placeholder="Select Country" | ||
required | ||
/> | ||
<div className="h-36" /> | ||
<ModalFooter | ||
loading={isLoading} | ||
onSubmit={handleSubmit((values) => mutate(values))} | ||
onVisibleChange={setModalVisible} | ||
primaryButton={{ text: "Proceed" }} | ||
/> | ||
</form> | ||
</Modal> | ||
</> | ||
); | ||
}; |
70 changes: 70 additions & 0 deletions
70
src/components/ManageCache/Sections/RevalidatePostedListingsByCountry.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"use client"; | ||
|
||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { useState } from "react"; | ||
import { useForm } from "react-hook-form"; | ||
import { toast } from "react-hot-toast"; | ||
import { z } from "zod"; | ||
import { revalidatePosedListingsByCountryAction } from "@/actions/cacheActions"; | ||
import { Modal, ModalFooter } from "@/components/Common"; | ||
import { AutocompleteController } from "@/components/FormElements/AutoComplete"; | ||
import { COUNTRIES } from "@/utils/countries"; | ||
import { LabelValue } from "@/utils/types"; | ||
|
||
const RevalidatePostedListingsByCountrySchema = z.object({ country: z.string() }); | ||
|
||
type RevalidatePostedListingsByCountryReq = z.infer<typeof RevalidatePostedListingsByCountrySchema>; | ||
|
||
export const RevalidatePostedListingsByCountry = () => { | ||
const [modalVisible, setModalVisible] = useState(false); | ||
|
||
const { handleSubmit, control } = useForm<RevalidatePostedListingsByCountryReq>({ | ||
resolver: zodResolver(RevalidatePostedListingsByCountrySchema), | ||
mode: "all", | ||
}); | ||
|
||
const { mutate, isLoading } = useMutation( | ||
(req: RevalidatePostedListingsByCountryReq) => { | ||
const countryCode = Object.keys(COUNTRIES).find((item) => COUNTRIES[item]?.[0] === req.country); | ||
return revalidatePosedListingsByCountryAction(countryCode!); | ||
}, | ||
{ | ||
onMutate: () => setModalVisible(false), | ||
onSuccess: () => toast.success(`Successfully revalidated posted listings`), | ||
onError: () => toast.error(`Failed to revalidate posted listings`), | ||
}, | ||
); | ||
|
||
const countryList: LabelValue[] = Object.keys(COUNTRIES).map((key) => ({ | ||
label: COUNTRIES[key]?.[0]!, | ||
value: COUNTRIES[key]?.[0]!, | ||
})); | ||
|
||
return ( | ||
<> | ||
<button className="btn btn-outline" disabled={isLoading} onClick={() => setModalVisible(true)}> | ||
Revalidate posted listings by country | ||
</button> | ||
<Modal onVisibleChange={setModalVisible} title="Revalidate posted listings by country" visible={!!modalVisible}> | ||
<form className="grid gap-1"> | ||
<AutocompleteController | ||
control={control} | ||
fieldName="country" | ||
label="Country" | ||
options={countryList} | ||
placeholder="Select Country" | ||
required | ||
/> | ||
<div className="h-36" /> | ||
<ModalFooter | ||
loading={isLoading} | ||
onSubmit={handleSubmit((values) => mutate(values))} | ||
onVisibleChange={setModalVisible} | ||
primaryButton={{ text: "Proceed" }} | ||
/> | ||
</form> | ||
</Modal> | ||
</> | ||
); | ||
}; |
54 changes: 54 additions & 0 deletions
54
src/components/ManageCache/Sections/RevalidateUserProfileDetails.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"use client"; | ||
|
||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { useState } from "react"; | ||
import { useForm } from "react-hook-form"; | ||
import { toast } from "react-hot-toast"; | ||
import { z } from "zod"; | ||
import { revalidateUserProfileDetails } from "@/actions/cacheActions"; | ||
import { Modal, ModalFooter } from "@/components/Common"; | ||
import { InputController } from "@/components/FormElements/Input"; | ||
|
||
const RevalidateUserProfileSchema = z.object({ userId: z.string() }); | ||
|
||
type RevalidateUserProfileSchemaReq = z.infer<typeof RevalidateUserProfileSchema>; | ||
|
||
export const RevalidateUserProfileDetails = () => { | ||
const [modalVisible, setModalVisible] = useState(false); | ||
|
||
const { handleSubmit, control } = useForm<RevalidateUserProfileSchemaReq>({ | ||
resolver: zodResolver(RevalidateUserProfileSchema), | ||
mode: "all", | ||
}); | ||
|
||
const { mutate, isLoading } = useMutation( | ||
(req: RevalidateUserProfileSchemaReq) => { | ||
return revalidateUserProfileDetails(req.userId); | ||
}, | ||
{ | ||
onMutate: () => setModalVisible(false), | ||
onSuccess: () => toast.success(`Successfully revalidated user profile`), | ||
onError: () => toast.error(`Failed to revalidate user profile`), | ||
}, | ||
); | ||
|
||
return ( | ||
<> | ||
<button className="btn btn-outline" disabled={isLoading} onClick={() => setModalVisible(true)}> | ||
Revalidate user profile details | ||
</button> | ||
<Modal onVisibleChange={setModalVisible} title="Revalidate user profile details" visible={!!modalVisible}> | ||
<form className="grid gap-1"> | ||
<InputController control={control} fieldName="userId" label="User ID" placeholder="User ID" required /> | ||
<ModalFooter | ||
loading={isLoading} | ||
onSubmit={handleSubmit((values) => mutate(values))} | ||
onVisibleChange={setModalVisible} | ||
primaryButton={{ text: "Proceed" }} | ||
/> | ||
</form> | ||
</Modal> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.