Skip to Content
BBRICKSv0.7.4
Recipes

Campaign change requests

Answer a brand's requests to change its campaign, and its request for the next campaign, with one reason dialog and a toast.

Each brand has one active campaign. Brands do not change it themselves: they ask, and PR approves or declines. This recipe answers those requests on the brand's campaign page and shows where they come from.

Requests on one brand's campaign

CampaignChangeRequests lists what the brand asked for; Approve is immediate (the row shows busy while it saves), Decline asks for a reason in one ReasonDialog first. NextCampaignCard answers the brand's request for its next campaign the same way. A toast says what happened.

Pinned to TRNDR presetPR theme
Code
import { useState } from 'react';
import { CampaignChangeRequests, NextCampaignCard, PageGrid, PageHeader, ReasonDialog, ToastRegion, type CampaignChangeRequest, type NextCampaign, type ToastMessage } from '@ergasti/bricks';
import { changeRequests } from './recipes';

const DECLINE_REASONS = ['Outside the campaign budget', 'Too close to the campaign end', 'Needs a call with the brand first'].map((r) => ({ value: r, label: r }));

function Requests() {
  const [requests, setRequests] = useState<CampaignChangeRequest[]>(changeRequests);
  const [next, setNext] = useState<NextCampaign | null>({ name: 'Ramadan 2027', from: '1 Feb 2027', to: '31 Mar 2027', commission: '18% of sale', status: 'waiting' });
  const [saving, setSaving] = useState<CampaignChangeRequest['id'] | null>(null);
  const [declining, setDeclining] = useState<CampaignChangeRequest | 'next' | null>(null);
  const [toast, setToast] = useState<ToastMessage | null>(null);
  const settle = (id: CampaignChangeRequest['id'], status: CampaignChangeRequest['status'], message: string) => {
    setSaving(id);
    window.setTimeout(() => {
      setRequests((all) => all.map((r) => (r.id === id ? { ...r, status } : r)));
      setSaving(null);
      setToast({ message });
    }, 700);
  };
  return (
    <PageGrid>
      <PageHeader title="Winter glow 2026" subtitle="Glow Lab · 1 Nov 2026 → 31 Jan 2027 · the brand is told about every change." />
      <PageGrid split="7-5" align="start">
        <CampaignChangeRequests
          brandName="Glow Lab" requests={requests} busy={(r) => r.id === saving}
          onApprove={(r) => settle(r.id, 'approved', `Approved: ${r.what} is now ${r.to}.`)}
          onDecline={(r) => setDeclining(r)}
        />
        <NextCampaignCard
          currentName="Winter glow 2026" next={next}
          onSchedule={() => { setNext(next && { ...next, status: 'scheduled' }); setToast({ message: 'Ramadan 2027 is scheduled.' }); }}
          onDecline={() => setDeclining('next')}
        />
      </PageGrid>
      <ReasonDialog
        open={declining !== null} onClose={() => setDeclining(null)}
        title={declining === 'next' ? 'Decline the next campaign?' : `Decline “${declining?.what ?? ''}”?`}
        sub="Glow Lab sees your reason and can ask again." reasons={DECLINE_REASONS} confirmLabel="Decline"
        onConfirm={({ reason }) => {
          if (declining === 'next') { setNext(null); setToast({ message: `Declined: ${reason}.` }); }
          else if (declining) settle(declining.id, 'declined', `Declined: ${reason}.`);
          setDeclining(null);
        }}
      />
      <ToastRegion toast={toast} onDismiss={() => setToast(null)} />
    </PageGrid>
  );
}

Steps

  1. List the requests. CampaignChangeRequests takes the brand's name and its requests (what, from, to, when, why, and a status). Waiting requests get Approve and Decline; answered ones show how they were answered.
  2. Approve straight away. onApprove(request) sends the change. Return true from busy(request) for the row being saved, so its buttons lock and say so.
  3. Decline with a reason. onDecline(request) opens one ReasonDialog for every decline (a list of reasons and an optional note); send the reason, then update the request's status.
  4. Answer the next campaign. NextCampaignCard shows what the brand asked for after the current campaign: onSchedule accepts it and onDecline goes through the same reason dialog. next={null} says nothing is requested.
  5. Lay it out. A PageGrid with split="7-5" puts the requests beside the next campaign, one column at 1180px and under.
  6. Say what happened. A ToastRegion message after each answer ("Approved: Discount per coupon is now 15% off").

Where requests come from

The affiliate programs list shows how many requests wait per brand (the waiting column of campaignColumns). CustomerAffiliatesSwitch turns customer affiliates on or off for every brand (turning off asks first), and CustomerAffiliatesCard is one brand's customer rate and link.

Where requests come from

The campaigns table (campaignColumns) shows how many requests wait per brand; the customer affiliates switch turns the program on for every brand, and CustomerAffiliatesCard is one brand's customer rate and link.

Pinned to TRNDR presetPR theme
Code
import { useState } from 'react';
import { Button, CustomerAffiliatesCard, CustomerAffiliatesSwitch, DataTable, Muted, PageGrid, PageHeader, campaignColumns, useLanguage, type CampaignRow } from '@ergasti/bricks';
import { campaigns } from './recipes';

function Programs() {
  const language = useLanguage();
  const [platformOn, setPlatformOn] = useState(true);
  const [linkOn, setLinkOn] = useState(true);
  const [rate, setRate] = useState('5');
  const [open, setOpen] = useState<CampaignRow | null>(null);
  return (
    <PageGrid>
      <PageHeader title="Affiliate programs" subtitle="One active campaign per brand. Brands request changes; only PR changes it." actions={<CustomerAffiliatesSwitch on={platformOn} onTurnOff={() => setPlatformOn(false)} onTurnOn={() => setPlatformOn(true)} />} />
      <DataTable label="Campaigns" rows={campaigns} rowKey={(r) => r.id} columns={campaignColumns(language)} onRowClick={setOpen} />
      {open && <Muted as="p" size="md">Opening {open.campaign.name} ({open.waiting} waiting)… <Button size="sm" variant="ghost" onClick={() => setOpen(null)}>Close</Button></Muted>}
      <CustomerAffiliatesCard
        brandName="Glow Lab" kind="percent" rate={rate} creatorRate="10" creatorRateLabel="10% of sale" customers={38} sales="21400.00"
        link="trndr.app/join?c=GL5mf" linkOn={linkOn} platformOn={platformOn}
        onSaveRate={({ rate: next }) => setRate(next)} onNewLink={() => {}} onToggleLink={setLinkOn}
      />
    </PageGrid>
  );
}

Related: PR campaign screen, PR affiliate programs screen.

On this page