Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Item Edit: Limit Name and Image Update #11200

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions components/common/EditNftModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@
:label="$t('mint.nft.art.label')"
required
>
<FormLogoField
v-model:file="image"
v-model:url="imageUrl"
/>
<NonRecommendFieldNotification
:show="imageChanged"
@undo="initImage"
>
<FormLogoField
v-model:file="image"
v-model:url="imageUrl"
/>
</NonRecommendFieldNotification>
</NeoField>

<!-- nft name -->
Expand All @@ -28,11 +33,16 @@
required
:error="!name"
>
<NeoInput
v-model="name"
required
:placeholder="$t('mint.nft.name.placeholder')"
/>
<NonRecommendFieldNotification
:show="name && nameChanged"
@undo="name = props.metadata?.name"
>
<NeoInput
v-model="name"
required
:placeholder="$t('mint.nft.name.placeholder')"
/>
</NonRecommendFieldNotification>
</NeoField>

<!-- nft description -->
Expand Down Expand Up @@ -91,17 +101,24 @@ const image = ref<File>()
const imageUrl = ref<string>()
const attributes = ref<Attribute[]>([])

const originalImageUrl = computed(() => sanitizeIpfsUrl(props.metadata?.image))

const nameChanged = computed(() => props.metadata?.name !== name.value)
const imageChanged = computed(() => originalImageUrl.value !== imageUrl.value)

const initImage = () => {
imageUrl.value = originalImageUrl.value
image.value = undefined
}

const disabled = computed(() => {
const hasImage = Boolean(imageUrl.value)
const isNameFilled = Boolean(name.value)

const nameChanged = props.metadata?.name !== name.value
const descriptionChanged = props.metadata?.description !== description.value
const imageChanged = Boolean(image.value)
const attributesChanged = JSON.stringify(attributes.value) !== JSON.stringify(props.metadata?.attributes || [])

return !hasImage || !isNameFilled
|| (!nameChanged && !descriptionChanged && !imageChanged && !attributesChanged)
|| (!nameChanged.value && !descriptionChanged && !imageChanged.value && !attributesChanged)
})

const editCollection = async () => {
Expand All @@ -118,8 +135,7 @@ const editCollection = async () => {

watch(isModalActive, (value) => {
if (value) {
imageUrl.value = sanitizeIpfsUrl(props.metadata?.image)
image.value = undefined
initImage()
name.value = props.metadata?.name
description.value = props.metadata?.description
attributes.value = structuredClone(toRaw(props.metadata?.attributes || []))
Expand Down
48 changes: 48 additions & 0 deletions components/common/NonRecommendFieldNotification.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template>
<div class="flex flex-col w-full">
<slot />
<div
v-if="show"
class="flex items-center gap-2 bg-yellow-50 border border-yellow-200 rounded-md p-3 !mt-2"
>
<NeoIcon
icon="warning"
class="text-yellow-500"
size="small"
/>

<div>
<p class="text-sm text-yellow-700">
{{ $t('mint.notRecommendedModify') }}
</p>
<div
v-if="!disabledUndo"
class="w-full flex justify-end"
>
<NeoButton
variant="text"
class="flex items-center gap-1 text-sm !text-yellow-600 hover:!text-yellow-700 capitalize"
@click="emit('undo')"
>
<NeoIcon
icon="undo"
size="small"
/>
{{ $t('general.undo') }}
</NeoButton>
</div>
</div>
</div>
</div>
</template>

<script lang="ts" setup>
import { NeoButton, NeoIcon } from '@kodadot1/brick'

defineProps<{
show: boolean
disabledUndo?: boolean
}>()

const emit = defineEmits(['undo'])
</script>
2 changes: 2 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@
"cancelled": "Transaction was cancelled",
"feesPaidIn": "You are paying fees in {0}"
},
"undo": "Undo",
"updateOnWebsiteSoon": "Update on website visible soon",
"usd": "USD",
"using": "using"
Expand Down Expand Up @@ -1358,6 +1359,7 @@
"message": "People will be able to buy your NFT."
}
},
"notRecommendedModify": "Please note that this field is not recommended to be modified as it may lead to misuse and confusion",
hassnian marked this conversation as resolved.
Show resolved Hide resolved
"progress": "In Progress",
"requiredDeposit": "A deposit of <strong>{0}</strong> is required to create a {1}. Please note, this initial deposit is refundable.",
"royalty": {
Expand Down
Loading