feat: add header channel selector & adding channel modal menu
This commit is contained in:
@@ -29,32 +29,19 @@ import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { creativesApi, channelsApi } from "@/lib/api";
|
||||
import { AlertCircle, Loader2, ArrowLeft, Info } from "lucide-react";
|
||||
import type { TargetChannel } from "@/lib/types/api";
|
||||
import { useTargetChannel } from "@/components/providers/target-channel-provider";
|
||||
|
||||
export default function CreateCreativePage() {
|
||||
const router = useRouter();
|
||||
const [channels, setChannels] = useState<TargetChannel[]>([]);
|
||||
const { selectedChannel } = useTargetChannel();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const [formData, setFormData] = useState({
|
||||
name: "",
|
||||
text: "",
|
||||
target_channel_id: "",
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
loadChannels();
|
||||
}, []);
|
||||
|
||||
const loadChannels = async () => {
|
||||
try {
|
||||
const response = await channelsApi.list();
|
||||
setChannels(response.target_channels.filter((c) => c.is_active));
|
||||
} catch (err) {
|
||||
console.error("Error loading channels:", err);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setError(null);
|
||||
@@ -75,14 +62,17 @@ export default function CreateCreativePage() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!formData.target_channel_id) {
|
||||
setError("Выберите целевой канал");
|
||||
if (!selectedChannel) {
|
||||
setError("Выберите целевой канал в верхнем меню");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setIsLoading(true);
|
||||
await creativesApi.create(formData);
|
||||
await creativesApi.create({
|
||||
...formData,
|
||||
target_channel_id: selectedChannel.id,
|
||||
});
|
||||
router.push("/creatives");
|
||||
} catch (err: any) {
|
||||
setError(err?.error?.message || "Ошибка создания креатива");
|
||||
@@ -151,26 +141,14 @@ export default function CreateCreativePage() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="target_channel_id">Целевой канал *</Label>
|
||||
<Select
|
||||
value={formData.target_channel_id}
|
||||
onValueChange={(value) =>
|
||||
setFormData({ ...formData, target_channel_id: value })
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Выберите канал" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{channels.map((channel) => (
|
||||
<SelectItem key={channel.id} value={channel.id}>
|
||||
{channel.title}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
{selectedChannel && (
|
||||
<Alert>
|
||||
<Info className="h-4 w-4" />
|
||||
<AlertDescription>
|
||||
Креатив будет создан для канала: <strong>{selectedChannel.title}</strong>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user