This commit is contained in:
Samandar Turgunboyev
2025-11-01 10:00:42 +05:00
parent 3f8b9881de
commit 08fd482242
5 changed files with 168 additions and 174 deletions

View File

@@ -330,11 +330,11 @@ const StepOne = ({
if (value.banner instanceof File) {
formData.append("image_banner", value.banner);
}
value.tarif.forEach((e, i) => {
value.tarif?.forEach((e, i) => {
formData.append(`tariff[${i}]tariff`, String(e.tariff));
formData.append(`tariff[${i}]price`, String(e.price));
});
value.transport.forEach((e, i) => {
value.transport?.forEach((e, i) => {
formData.append(`transports[${i}]transport`, String(e.transport));
formData.append(`transports[${i}]price`, String(e.price));
});
@@ -1005,11 +1005,10 @@ const StepOne = ({
onChange={(e) => {
const raw = e.target.value.replace(/\D/g, "");
const num = Number(raw);
const updatedTransport = form
.getValues("tarif")
.map((t, i) =>
i === idx ? { ...t, price: num } : t,
);
const currentTarifs = form.getValues("tarif") || [];
const updatedTransport = currentTarifs.map((t, i) =>
i === idx ? { ...t, price: num } : t,
);
form.setValue("tarif", updatedTransport);
@@ -1024,7 +1023,7 @@ const StepOne = ({
<button
type="button"
onClick={() => {
const current = form.getValues("tarif");
const current = form.getValues("tarif") || [];
form.setValue(
"tarif",
current.filter((_, i) => i !== idx),
@@ -1057,15 +1056,14 @@ const StepOne = ({
<CommandList>
<CommandGroup heading={t("Mavjud tariflar")}>
{tariff?.data?.data?.results?.map((item: any) => {
const selected = form
.getValues("tarif")
.some((t) => t.tariff === item.id);
const currentTarifs = form.getValues("tarif") || [];
const selected = currentTarifs.some((t) => t.tariff === item.id);
return (
<CommandItem
key={item.id}
onSelect={() => {
const current = form.getValues("tarif");
const current = form.getValues("tarif") || [];
if (selected) {
form.setValue(
"tarif",
@@ -1139,11 +1137,10 @@ const StepOne = ({
onChange={(e) => {
const raw = e.target.value.replace(/\D/g, "");
const num = Number(raw);
const updatedTransport = form
.getValues("transport")
.map((t, i) =>
i === idx ? { ...t, price: num } : t,
);
const currentTransports = form.getValues("transport") || [];
const updatedTransport = currentTransports.map((t, i) =>
i === idx ? { ...t, price: num } : t,
);
form.setValue("transport", updatedTransport);
@@ -1158,7 +1155,7 @@ const StepOne = ({
<button
type="button"
onClick={() => {
const current = form.getValues("transport");
const current = form.getValues("transport") || [];
form.setValue(
"transport",
current.filter((_, i) => i !== idx),
@@ -1193,15 +1190,14 @@ const StepOne = ({
<CommandList>
<CommandGroup heading={t("Mavjud transportlar")}>
{transport?.data?.data?.results?.map((item: any) => {
const selected = form
.getValues("transport")
.some((t) => t.transport === item.id);
const currentTransports = form.getValues("transport") || [];
const selected = currentTransports.some((t) => t.transport === item.id);
return (
<CommandItem
key={item.id}
onSelect={() => {
const current = form.getValues("transport");
const current = form.getValues("transport") || [];
if (selected) {
form.setValue(
"transport",

View File

@@ -145,7 +145,7 @@ const Tours = ({ user }: { user: Role }) => {
<Button
onClick={() => navigate("/tours/create")}
variant="default"
disabled={user !== "tour_admin"}
// disabled={user !== "tour_admin"}
>
<PlusCircle className="w-5 h-5 mr-2" /> {t("Yangi tur qo'shish")}
</Button>