-
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 price per advertiser (#900)
* feat: allow for price-per-advertiser * fix: tests * fix: add default * fix: update for new pricing structure * fix: no need for default, use prices when switching * test: validate price schema * test: validate price schema pt 2 * fix: flaky test
- Loading branch information
1 parent
b333376
commit 1639804
Showing
15 changed files
with
497 additions
and
188 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
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
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.