|
62 | 62 | <label for="pat-expires"> |
63 | 63 | <span class="font-semibold">{{ formatMessage(createModalMessages.expiresLabel) }}</span> |
64 | 64 | </label> |
65 | | - <DatePicker id="pat-expires" v-model="expires" show-today wrapper-class="w-full" /> |
| 65 | + <DatePicker |
| 66 | + id="pat-expires" |
| 67 | + v-model="expires" |
| 68 | + :min-date="minimumPatExpiry" |
| 69 | + show-today |
| 70 | + wrapper-class="w-full" |
| 71 | + /> |
66 | 72 | </div> |
67 | 73 |
|
68 | 74 | <div class="ml-auto mt-4 flex gap-2"> |
|
73 | 79 | </button> |
74 | 80 | </ButtonStyled> |
75 | 81 | <ButtonStyled v-if="editPatId !== null" color="brand"> |
76 | | - <button :disabled="loading || !name || !expires" @click="editPat"> |
| 82 | + <button :disabled="loading || !name || !isExpiryInFuture" @click="editPat"> |
77 | 83 | <SaveIcon /> |
78 | 84 | {{ formatMessage(commonMessages.saveChangesButton) }} |
79 | 85 | </button> |
80 | 86 | </ButtonStyled> |
81 | 87 | <ButtonStyled v-else color="brand"> |
82 | | - <button :disabled="loading || !name || !expires" @click="createPat"> |
| 88 | + <button :disabled="loading || !name || !isExpiryInFuture" @click="createPat"> |
83 | 89 | <PlusIcon /> |
84 | 90 | {{ formatMessage(createModalMessages.action) }} |
85 | 91 | </button> |
|
123 | 129 | <strong>{{ pat.name }}</strong> |
124 | 130 | </div> |
125 | 131 | <div> |
126 | | - <template v-if="pat.access_token"> |
127 | | - <CopyCode :text="pat.access_token" /> |
| 132 | + <template v-if="createdPatTokens[pat.id] || pat.access_token"> |
| 133 | + <CopyCode :text="createdPatTokens[pat.id] || pat.access_token" /> |
128 | 134 | </template> |
129 | 135 | <template v-else> |
130 | 136 | <span v-tooltip="pat.last_used ? formatDateTime(pat.last_used) : null"> |
@@ -331,12 +337,17 @@ useHead({ |
331 | 337 | const data = useNuxtApp() |
332 | 338 | const { scopesToLabels } = useScopes() |
333 | 339 | const patModal = ref() |
| 340 | +const minimumPatExpiry = data.$dayjs().add(1, 'day').format('YYYY-MM-DD') |
334 | 341 |
|
335 | 342 | const editPatId = ref(null) |
336 | 343 |
|
337 | 344 | const name = ref(null) |
338 | 345 | const scopesVal = ref(BigInt(0)) |
339 | 346 | const expires = ref(null) |
| 347 | +const createdPatTokens = ref({}) |
| 348 | +const isExpiryInFuture = computed( |
| 349 | + () => expires.value && data.$dayjs(expires.value).isAfter(data.$dayjs(), 'day'), |
| 350 | +) |
340 | 351 |
|
341 | 352 | const deletePatIndex = ref(null) |
342 | 353 |
|
@@ -415,6 +426,9 @@ async function createPat() { |
415 | 426 | scopes: Number(scopesVal.value), |
416 | 427 | expires: data.$dayjs(expires.value).toISOString(), |
417 | 428 | }) |
| 429 | + if (res.access_token) { |
| 430 | + createdPatTokens.value[res.id] = res.access_token |
| 431 | + } |
418 | 432 | queryClient.setQueryData(['pat'], (old) => [...(old || []), res]) |
419 | 433 | patModal.value.hide() |
420 | 434 | } catch (err) { |
|
0 commit comments