-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow for price-per-advertiser
- Loading branch information
1 parent
4f256ba
commit 9018ac3
Showing
8 changed files
with
389 additions
and
153 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,41 @@ | ||
import { useAdvertiser } from "auth/hooks/queries/useAdvertiser"; | ||
import { | ||
AdvertiserPriceFragment, | ||
useAdvertiserPricesQuery, | ||
} from "graphql/advertiser.generated"; | ||
import { useState } from "react"; | ||
import { IAdvertiser } from "auth/context/auth.interface"; | ||
import _ from "lodash"; | ||
|
||
export type AdvertiserWithPrices = IAdvertiser & { | ||
prices: AdvertiserPriceFragment[]; | ||
}; | ||
export function useAdvertiserWithPrices() { | ||
const { advertiser } = useAdvertiser(); | ||
const [data, setData] = useState<AdvertiserWithPrices>({ | ||
...advertiser, | ||
prices: [], | ||
}); | ||
const [error, setError] = useState<string>(); | ||
|
||
const { loading } = useAdvertiserPricesQuery({ | ||
variables: { id: advertiser.id }, | ||
onCompleted(data) { | ||
const prices = data.advertiser?.prices ?? []; | ||
if (_.isEmpty(prices)) { | ||
setError("Unable to create a new campaign"); | ||
return; | ||
} | ||
|
||
setData({ | ||
...advertiser, | ||
prices, | ||
}); | ||
}, | ||
onError(error) { | ||
setError(error.message); | ||
}, | ||
}); | ||
|
||
return { data, loading, error }; | ||
} |
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
Oops, something went wrong.