Commit 7f3824fa authored by Bitcoin Please's avatar Bitcoin Please
Browse files

Added campaign update to store.

parent 7a534bdf
......@@ -8,6 +8,7 @@ import getCampaigns from './campaigns/getters/getCampaigns'
/* Import modules (actions). */
import updateAsset from './campaigns/actions/updateAsset'
import updateCampaign from './campaigns/actions/updateCampaign'
/* Import modules (mutations). */
import setAsset from './campaigns/mutations/setAsset'
......@@ -34,6 +35,7 @@ const getters = {
/* Actions. */
const actions = {
updateAsset,
updateCampaign,
}
/* Mutations. */
......
/* Import modules. */
import superagent from 'superagent'
/**
* Update Campaign
*/
const updateCampaign = async ({ rootGetters }, _campaign) => {
// console.log('UPDATE CAMPAIGN:', _campaign)
const signedPkg = rootGetters['profile/getSignedMessage'](JSON.stringify(_campaign))
// console.log('SIGNED PACKAGE', signedPkg)
/* Set api target. */
const target = 'https://api.causes.cash/v1/campaigns'
const result = await superagent
.put(target)
.send(signedPkg)
// console.log('RESULT', result)
/* Return result. */
return result
}
/* Export module. */
export default updateCampaign
......@@ -15,7 +15,7 @@
</tr>
<tr v-for="item of budget" :key="item.txid">
<td>{{item.label}}</td>
<td>{{item.budgetAmount}}</td>
<td>{{item.amount}}</td>
<td>{{item.comments}}</td>
</tr>
<!-- <tr>
......@@ -43,7 +43,7 @@
</tr>
<tr v-for="item of expenses" :key="item.txid">
<td>{{item.label}}</td>
<td>{{item.expensesAmount}}</td>
<td>{{item.amount}}</td>
<td>{{item.comments}}</td>
</tr>
<!-- <tr>
......@@ -65,6 +65,7 @@ export default {
data: () => {
return {
budget: [],
expenses: [],
}
},
created: function () {
......@@ -72,11 +73,21 @@ export default {
const budget = {
txid: 'some-random-transaction-id',
label: 'Development',
budgetAmount: '100%',
amount: '100%',
comments: 'To be determined',
}
this.budget.push(budget)
/* Sample expenses. */
const expense = {
txid: 'some-random-transaction-id',
label: 'Food',
amount: '$10',
comments: 'To be determined',
}
this.expenses.push(expense)
},
}
</script>
......
......@@ -2,20 +2,76 @@
<div id="guide" class="tabs">
<h2>Campaign Guide</h2>
<p>
Looks like there aren't any frequently asked questions yet.
Ask the project creator directly.
</p>
<div class="mt-3" v-html="guideDisplay" />
<a href="javascript://" class="btn-primary">Ask a question</a>
<!-- <a href="javascript://" class="btn-primary">Ask a question</a> -->
</div>
</template>
<script>
/* Initialize vuex. */
import { mapActions, mapGetters } from 'vuex'
export default {
props: {
campaign: Object,
}
},
data: () => {
return {
ownerSlug: null,
extSlug: null,
guide: null,
}
},
watch: {
campaign: function (_campaign) {
if (_campaign && _campaign.guide) {
console.log('CAMPAIGN HAS CHANGED, UPDATE GUIDE!!', _campaign)
if (_campaign && _campaign.guide) {
/* Set summary. */
this.guide = _campaign.guide
console.log('GUIDE', this.guide)
}
}
},
},
computed: {
...mapGetters('utils', [
'getMarkdown',
]),
/**
* Guide Display
*/
guideDisplay() {
/* Validate guide. */
if (!this.guide) {
return null
}
/* Return summary (in markdown). */
return this.getMarkdown(this.guide)
},
},
methods: {
...mapActions('campaigns', [
'updateAsset',
]),
},
created: async function () {
/* Validate guide. */
if (this.campaign && this.campaign.guide) {
/* Set summary. */
this.guide = this.campaign.guide
console.log('GUIDE', this.guide)
}
},
}
</script>
......
......@@ -2,8 +2,7 @@
<div id="news" class="tabs comment-area">
<!-- <h3 class="comments-title">New &amp; Noteworthy</h3> -->
<ol class="comments-list">
<ol v-if="articleList" class="comments-list">
<li v-for="article of articleList" :key="article.id" class="comment clearfix">
<div class="comment-body">
<div class="comment-avatar">
......@@ -31,8 +30,11 @@
</div>
</div>
</li>
</ol>
<div v-else class="campaigns">
There is no news available
</div>
</div>
</template>
......@@ -66,6 +68,10 @@ export default {
]),
articleList() {
if (!this.articles || this.articles.length === 0) {
return null
}
const articles = this.articles.map(article => {
/* Format data. */
article.timeAgo = moment.unix(article.createdAt).format('ll')
......@@ -85,42 +91,24 @@ export default {
]),
},
created: async function () {
/* Set owner slug. */
this.ownerSlug = this.$route.params.pathMatch.toLowerCase()
// console.log('OWNER SLUG', this.ownerSlug)
/* Set extended slug. */
this.extSlug = this.$route.params.extSlug
// console.log('EXT SLUG', this.extSlug)
/* Validate slug. */
if (this.ownerSlug && this.extSlug) {
/* Set slug. */
const slug = this.extSlug.slice(0, this.extSlug.lastIndexOf('-'))
/* Set campaign. */
this.campaign = await this.getCampaign(this.ownerSlug, slug)
// console.log('NEWS (campaign):', this.campaign)
/* Validate news. */
if (this.campaign && this.campaign.news) {
/* Set summary. */
this.news = this.campaign.news
// console.log('NEWS', this.news)
/* Add each news article. */
this.news.forEach(news => {
this.articles.push({
id: news.id,
title: news.title,
summary: news.summary,
avatar: news.avatar,
url: news.url,
createdAt: news.createdAt,
})
created: function () {
/* Validate news. */
if (this.campaign && this.campaign.news) {
/* Set summary. */
this.news = this.campaign.news
console.log('NEWS', this.news)
/* Add each news article. */
this.news.forEach(news => {
this.articles.push({
id: news.id,
title: news.title,
summary: news.summary,
avatar: news.avatar,
url: news.url,
createdAt: news.createdAt,
})
}
})
}
},
......
......@@ -85,42 +85,24 @@ export default {
]),
},
created: async function () {
/* Set owner slug. */
this.ownerSlug = this.$route.params.pathMatch.toLowerCase()
// console.log('OWNER SLUG', this.ownerSlug)
/* Set extended slug. */
this.extSlug = this.$route.params.extSlug
// console.log('EXT SLUG', this.extSlug)
/* Validate slug. */
if (this.ownerSlug && this.extSlug) {
/* Set slug. */
const slug = this.extSlug.slice(0, this.extSlug.lastIndexOf('-'))
/* Set campaign. */
this.campaign = await this.getCampaign(this.ownerSlug, slug)
// console.log('NEWS (campaign):', this.campaign)
/* Validate premium. */
if (this.campaign && this.campaign.premium) {
/* Set summary. */
this.premium = this.campaign.premium
// console.log('NEWS', this.premium)
/* Add each premium item. */
this.premium.forEach(item => {
this.items.push({
id: item.id,
title: item.title,
summary: item.summary,
avatar: item.avatar,
url: item.url,
createdAt: item.createdAt,
})
created: function () {
/* Validate news. */
if (this.campaign && this.campaign.premium) {
/* Set summary. */
this.premium = this.campaign.premium
console.log('NEWS', this.premium)
/* Add each premium article. */
this.premium.forEach(premium => {
this.articles.push({
id: premium.id,
title: premium.title,
summary: premium.summary,
avatar: premium.avatar,
url: premium.url,
createdAt: premium.createdAt,
})
}
})
}
},
......
......@@ -26,13 +26,6 @@
</p>
</div> -->
<input
type="submit"
class="btn-primary"
value="Save & Continue"
@click="save"
>
<div class="field">
<label for="projecttitle">Project Title</label>
......
......@@ -318,6 +318,12 @@
</div>
</div>
<input
type="submit"
class="btn-primary"
value="Save & Continue"
@click="save"
>
</form>
</div>
</section>
......@@ -343,6 +349,17 @@ export default {
// fundId: null,
// referrerId: null,
videoCaption: null,
videoDescription: null,
photo1Caption: null,
photo2Caption: null,
photo3Caption: null,
photo1Url: null,
photo2Url: null,
photo3Url: null,
news: [{
id: null,
title: null,
......@@ -378,9 +395,59 @@ export default {
},
methods: {
...mapActions('campaigns', [
'updateAsset',
'updateCampaign',
]),
/**
* Save
*/
async save() {
/* Set campaign id. */
const campaignId = this.campaign.id
/* Set description. */
const summary = this.summary
/* Set description. */
const description = this.quillDesc.getText()
/* Set images. */
const images = {
main: this.photo1Url || null,
cover: this.photo1Url || null,
gallery: [
this.photo2Url || null,
this.photo3Url || null,
]
}
const pkg = {
campaignId,
summary,
description,
images,
}
console.log('PACKAGE', pkg)
const signedPkg = this.getSignedMessage(JSON.stringify(pkg))
console.log('SIGNED PACKAGE', signedPkg)
// this.updateCampaign
/* Set api target. */
// const target = 'https://api.causes.cash/v1/campaigns'
// const target = 'http://localhost:6767/v1/campaigns'
// const result = await superagent
// .put(target)
// .send(signedPkg)
// console.log('RESULT', result)
// if (result.ok && !result.error) {
// alert('Campaign updated successfully!')
// }
},
},
mounted: function () {
//
......@@ -404,8 +471,10 @@ export default {
this.campaign = await this.getCampaign(this.ownerSlug, this.slug)
console.log('SOCIAL (campaign):', this.campaign)
// FOR DEV ONLY
this.news[0].title = this.campaign.news[0].title
if (this.campaign.news) {
// FOR DEV ONLY
this.news[0].title = this.campaign.news[0].title
}
}
},
}
......
......@@ -41,12 +41,18 @@
<label>Project guide</label>
<span class="label-desc">
Use your project guide to help users when navigating through your camapaign.
Use your project guide to help users when navigating through your campaign.
</span>
<div id="guide-editor" class="editor"></div>
</div>
<input
type="submit"
class="btn-primary"
value="Save & Continue"
@click="save"
>
</form>
</div>
</section>
......@@ -57,9 +63,6 @@
/* Initialize vuex. */
import { mapActions, mapGetters } from 'vuex'
/* Import modules. */
import superagent from 'superagent'
export default {
components: {
//
......@@ -75,17 +78,6 @@ export default {
summary: null,
videoCaption: null,
videoDescription: null,
photo1Caption: null,
photo2Caption: null,
photo3Caption: null,
photo1Url: null,
photo2Url: null,
photo3Url: null,
quillDesc: null,
quillGuide: null,
}
......@@ -103,7 +95,7 @@ export default {
},
methods: {
...mapActions('campaigns', [
'updateAsset',
'updateCampaign',
]),
/**
......@@ -119,6 +111,9 @@ export default {
/* Set description. */
const description = this.quillDesc.getText()
/* Set guide. */
const guide = this.quillGuide.getText()
/* Set images. */
const images = {
main: this.photo1Url || null,
......@@ -129,26 +124,20 @@ export default {
]
}
const pkg = {
const campaign = {
campaignId,
summary,
description,
guide,
images,
}
console.log('PACKAGE', pkg)
console.log('WRITE (campaign):', campaign)
const signedPkg = this.getSignedMessage(JSON.stringify(pkg))
console.log('SIGNED PACKAGE', signedPkg)
/* Set api target. */
// const target = 'https://api.causes.cash/v1/campaigns'
const target = 'http://localhost:6767/v1/campaigns'
const result = await superagent
.put(target)
.send(signedPkg)
console.log('RESULT', result)
/* Request update. */
const result = await this.updateCampaign(campaign)
console.log('WRITE UPDATE (result):')
/* Handle result. */
if (result.ok && !result.error) {
alert('Campaign updated successfully!')
}
......@@ -196,6 +185,12 @@ export default {
this.quillDesc.insertText(0, this.campaign.description)
}
/* Validate guide. */
if (this.campaign && this.campaign.guide) {
/* Add guide to editor. */
this.quillGuide.insertText(0, this.campaign.guide)
}
/* Validate media. */
if (this.campaign && this.campaign.media) {
this.photo1Url = this.campaign.media.main
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment